#include <glib.h>

#define BASE64_1   "Cg=="
#define BASE64_2_1 "Cg="
#define BASE64_2_2 "="

int main () {
  gsize r;
  gsize i;
  gint state;
  guint save;
  guint8 decoded_1[sizeof (BASE64_1) * 4 / 3];
  guint8 decoded_2[(sizeof (BASE64_2_1) + sizeof (BASE64_2_2)) * 4 / 3];

  state = 0;
  save = 0;

  r = g_base64_decode_step (BASE64_1, sizeof (BASE64_1), decoded_1, &state,
      &save);

  g_print ("round 1\n");
  for (i = 0; i < r; i++) {
    g_print ("0x%02x,", decoded_1[i]);
  }
  g_print ("\n");

  state = 0;
  save = 0;

  g_print ("round 2\n");
  r = g_base64_decode_step (BASE64_2_1, sizeof (BASE64_2_1), decoded_2, &state,
      &save);
  i  = g_base64_decode_step (BASE64_2_2, sizeof (BASE64_2_2), decoded_2 + r,
      &state, &save);
  r += i;
  for (i = 0; i < r; i++) {
    g_print ("0x%02x,", decoded_2[i]);
  }
  g_print ("\n");

  return 0;
}
