#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const);
void cs_fprint_base64(FILE *f, const unsigned char *src, int src_len) {
  static const char *b64 =
      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  int i, j, a, b, c;
  for (i = j = 0; i < src_len; i += 3) {
    a = src[i];
    b = i + 1 >= src_len ? 0 : src[i + 1];
    c = i + 2 >= src_len ? 0 : src[i + 2];
    do {
      fprintf(f, "%c", (b64[a >> 2]));
      j++;
    } while (0);
    do {
      fprintf(f, "%c", (b64[((a & 3) << 4) | (b >> 4)]));
      j++;
    } while (0);
    if (i + 1 < src_len) {
      do {
        fprintf(f, "%c", (b64[(b & 15) << 2 | (c >> 6)]));
        j++;
      } while (0);
    }
    if (i + 2 < src_len) {
      do {
        fprintf(f, "%c", (b64[c & 63]));
        j++;
      } while (0);
    }
  }
  while (j % 4 != 0) {
    do {
      fprintf(f, "%c", ('='));
      j++;
    } while (0);
  };
}


x86 assembly (clang, -O0):
<cs_fprint_base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12c6 <cs_fprint_base64+0x1b6>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cmp    -0x14(%rbp),%eax
jl     1165 <cs_fprint_base64+0x55>
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
jmp    1179 <cs_fprint_base64+0x69>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
cmp    -0x14(%rbp),%eax
jl     1198 <cs_fprint_base64+0x88>
xor    %eax,%eax
mov    %eax,-0x30(%rbp)
jmp    11ac <cs_fprint_base64+0x9c>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e6b(%rip),%rax
mov    -0x20(%rbp),%ecx
sar    $0x2,%ecx
movslq %ecx,%rcx
lea    0xe74(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e4 <cs_fprint_base64+0xd4>
mov    -0x8(%rbp),%rdi
mov    0x2e39(%rip),%rax
mov    -0x20(%rbp),%ecx
and    $0x3,%ecx
shl    $0x4,%ecx
mov    -0x24(%rbp),%edx
sar    $0x4,%edx
or     %edx,%ecx
movslq %ecx,%rcx
lea    0xe37(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cmp    -0x14(%rbp),%eax
jge    126d <cs_fprint_base64+0x15d>
jmp    1230 <cs_fprint_base64+0x120>
mov    -0x8(%rbp),%rdi
mov    0x2ded(%rip),%rax
mov    -0x24(%rbp),%ecx
and    $0xf,%ecx
shl    $0x2,%ecx
mov    -0x28(%rbp),%edx
sar    $0x6,%edx
or     %edx,%ecx
movslq %ecx,%rcx
lea    0xdeb(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    126d <cs_fprint_base64+0x15d>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
cmp    -0x14(%rbp),%eax
jge    12b3 <cs_fprint_base64+0x1a3>
jmp    1281 <cs_fprint_base64+0x171>
mov    -0x8(%rbp),%rdi
mov    0x2d9c(%rip),%rax
mov    -0x28(%rbp),%ecx
and    $0x3f,%ecx
movslq %ecx,%rcx
lea    0xda5(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12b3 <cs_fprint_base64+0x1a3>
jmp    12b8 <cs_fprint_base64+0x1a8>
mov    -0x18(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x18(%rbp)
jmp    1131 <cs_fprint_base64+0x21>
jmp    12cb <cs_fprint_base64+0x1bb>
mov    -0x1c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1307 <cs_fprint_base64+0x1f7>
jmp    12e4 <cs_fprint_base64+0x1d4>
mov    -0x8(%rbp),%rdi
lea    0xd52(%rip),%rsi
mov    $0x3d,%edx
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12cb <cs_fprint_base64+0x1bb>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cs_fprint_base64>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %edx,%edx
jle    1278 <cs_fprint_base64+0x168>
mov    %edx,%r13d
mov    %rdi,%r14
mov    %edx,%eax
mov    %rax,0x20(%rsp)
xor    %ebp,%ebp
mov    $0x1,%ebx
lea    0xebf(%rip),%r12
mov    %edx,0xc(%rsp)
mov    %rsi,0x18(%rsp)
jmp    117c <cs_fprint_base64+0x6c>
nopl   0x0(%rax)
and    $0x3f,%r14d
movsbl (%r14,%r12,1),%edi
mov    %r15,%r14
mov    %r15,%rsi
call   1030 <fputc@plt>
add    $0x1,%ebp
mov    0x18(%rsp),%rsi
add    $0x3,%rbx
lea    -0x1(%rbx),%eax
cmp    %r13d,%eax
jge    1249 <cs_fprint_base64+0x139>
mov    %ebp,0x14(%rsp)
mov    $0x0,%r15d
cmp    0x20(%rsp),%rbx
jge    1192 <cs_fprint_base64+0x82>
movzbl (%rsi,%rbx,1),%r15d
mov    %r14,%rbp
lea    0x1(%rbx),%eax
xor    %r14d,%r14d
mov    %eax,0x10(%rsp)
cmp    %r13d,%eax
jge    11aa <cs_fprint_base64+0x9a>
movzbl 0x1(%rsi,%rbx,1),%r14d
movzbl -0x1(%rsi,%rbx,1),%r13d
mov    %r13,%rax
shr    $0x2,%rax
movsbl (%rax,%r12,1),%edi
mov    %rbp,%rsi
call   1030 <fputc@plt>
shl    $0x4,%r13d
and    $0x30,%r13d
mov    %r15d,%eax
shr    $0x4,%rax
or     %r13,%rax
movsbl (%r12,%rax,1),%edi
mov    %rbp,%rsi
call   1030 <fputc@plt>
cmp    0x20(%rsp),%rbx
jge    1220 <cs_fprint_base64+0x110>
and    $0xf,%r15d
mov    %r14d,%eax
shr    $0x6,%eax
lea    (%rax,%r15,4),%eax
movsbl (%rax,%r12,1),%edi
mov    %rbp,%r15
mov    %rbp,%rsi
call   1030 <fputc@plt>
mov    0x14(%rsp),%ebp
add    $0x3,%ebp
jmp    122a <cs_fprint_base64+0x11a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%r15
mov    0x14(%rsp),%ebp
add    $0x2,%ebp
mov    0xc(%rsp),%r13d
mov    0x10(%rsp),%eax
cmp    %r13d,%eax
jl     1150 <cs_fprint_base64+0x40>
mov    0x18(%rsp),%rsi
mov    %r15,%r14
jmp    116c <cs_fprint_base64+0x5c>
test   $0x3,%bpl
je     1278 <cs_fprint_base64+0x168>
add    $0x1,%ebp
mov    %ebp,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x3d,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
add    $0x1,%ebx
test   $0x3,%bpl
mov    %ebx,%ebp
jne    1260 <cs_fprint_base64+0x150>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@cs_fprint_base64.b64 = internal global i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i32 0, i32 0)
@.str = [65 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\00"
@.str.1 = [3 x i8] c"%c\00"
define void @cs_fprint_base64(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %8
store i32 0, i32* %7
br label %12
12: ; preds = %121, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %124
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
store i32 %22, i32* %9
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
%25 = load i32, i32* %6
%26 = icmp sge i32 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %16
br label %36
28: ; preds = %16
%29 = load i8*, i8** %5
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
br label %36
36: ; preds = %28, %27
%37 = phi i32 [ 0, %27 ], [ %35, %28 ]
store i32 %37, i32* %10
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 2
%40 = load i32, i32* %6
%41 = icmp sge i32 %39, %40
br i1 %41, label %42, label %43
42: ; preds = %36
br label %51
43: ; preds = %36
%44 = load i8*, i8** %5
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 2
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %44, i64 %47
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
br label %51
51: ; preds = %43, %42
%52 = phi i32 [ 0, %42 ], [ %50, %43 ]
store i32 %52, i32* %11
br label %53
53: ; preds = %51
%54 = load i32*, i32** %4
%55 = load i8*, i8** @cs_fprint_base64.b64
%56 = load i32, i32* %9
%57 = ashr i32 %56, 2
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %55, i64 %58
%60 = load i8, i8* %59
%61 = call i32 @fprintf(i32* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %60)
%62 = load i32, i32* %8
%63 = add nsw i32 %62, 1
store i32 %63, i32* %8
br label %64
64: ; preds = %53
br label %65
65: ; preds = %64
%66 = load i32*, i32** %4
%67 = load i8*, i8** @cs_fprint_base64.b64
%68 = load i32, i32* %9
%69 = and i32 %68, 3
%70 = shl i32 %69, 4
%71 = load i32, i32* %10
%72 = ashr i32 %71, 4
%73 = or i32 %70, %72
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %67, i64 %74
%76 = load i8, i8* %75
%77 = call i32 @fprintf(i32* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %76)
%78 = load i32, i32* %8
%79 = add nsw i32 %78, 1
store i32 %79, i32* %8
br label %80
80: ; preds = %65
%81 = load i32, i32* %7
%82 = add nsw i32 %81, 1
%83 = load i32, i32* %6
%84 = icmp slt i32 %82, %83
br i1 %84, label %85, label %102
85: ; preds = %80
br label %86
86: ; preds = %85
%87 = load i32*, i32** %4
%88 = load i8*, i8** @cs_fprint_base64.b64
%89 = load i32, i32* %10
%90 = and i32 %89, 15
%91 = shl i32 %90, 2
%92 = load i32, i32* %11
%93 = ashr i32 %92, 6
%94 = or i32 %91, %93
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8, i8* %88, i64 %95
%97 = load i8, i8* %96
%98 = call i32 @fprintf(i32* %87, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %97)
%99 = load i32, i32* %8
%100 = add nsw i32 %99, 1
store i32 %100, i32* %8
br label %101
101: ; preds = %86
br label %102
102: ; preds = %101, %80
%103 = load i32, i32* %7
%104 = add nsw i32 %103, 2
%105 = load i32, i32* %6
%106 = icmp slt i32 %104, %105
br i1 %106, label %107, label %120
107: ; preds = %102
br label %108
108: ; preds = %107
%109 = load i32*, i32** %4
%110 = load i8*, i8** @cs_fprint_base64.b64
%111 = load i32, i32* %11
%112 = and i32 %111, 63
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds i8, i8* %110, i64 %113
%115 = load i8, i8* %114
%116 = call i32 @fprintf(i32* %109, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %115)
%117 = load i32, i32* %8
%118 = add nsw i32 %117, 1
store i32 %118, i32* %8
br label %119
119: ; preds = %108
br label %120
120: ; preds = %119, %102
br label %121
121: ; preds = %120
%122 = load i32, i32* %7
%123 = add nsw i32 %122, 3
store i32 %123, i32* %7
br label %12
124: ; preds = %12
br label %125
125: ; preds = %135, %124
%126 = load i32, i32* %8
%127 = srem i32 %126, 4
%128 = icmp ne i32 %127, 0
br i1 %128, label %129, label %136
129: ; preds = %125
br label %130
130: ; preds = %129
%131 = load i32*, i32** %4
%132 = call i32 @fprintf(i32* %131, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext 61)
%133 = load i32, i32* %8
%134 = add nsw i32 %133, 1
store i32 %134, i32* %8
br label %135
135: ; preds = %130
br label %125
136: ; preds = %125
ret void
}

LLVM IR (-O2):
@.str = [65 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\00"
define void @cs_fprint_base64(i32* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %81
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %10
7: ; preds = %70
%8 = and i32 %71, 3
%9 = icmp eq i32 %8, 0
br i1 %9, label %81, label %75
10: ; preds = %5, %70
%11 = phi i64 [ 0, %5 ], [ %72, %70 ]
%12 = phi i32 [ 0, %5 ], [ %71, %70 ]
%13 = getelementptr inbounds i8, i8* %1, i64 %11
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = add nuw nsw i64 %11, 1
%17 = icmp slt i64 %16, %6
br i1 %17, label %18, label %22
18: ; preds = %10
%19 = getelementptr inbounds i8, i8* %1, i64 %16
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
br label %22
22: ; preds = %10, %18
%23 = phi i32 [ %21, %18 ], [ 0, %10 ]
%24 = add nuw nsw i64 %11, 2
%25 = trunc i64 %24 to i32
%26 = icmp slt i32 %25, %2
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = getelementptr inbounds i8, i8* %1, i64 %24
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
br label %31
31: ; preds = %22, %27
%32 = phi i32 [ %30, %27 ], [ 0, %22 ]
%33 = lshr i32 %15, 2
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = tail call i32 @fputc(i32 %37, i32* %0)
%39 = shl nuw nsw i32 %15, 4
%40 = and i32 %39, 48
%41 = lshr i32 %23, 4
%42 = or i32 %41, %40
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = tail call i32 @fputc(i32 %46, i32* %0)
%48 = add nsw i32 %12, 2
br i1 %17, label %49, label %60
49: ; preds = %31
%50 = shl nuw nsw i32 %23, 2
%51 = and i32 %50, 60
%52 = lshr i32 %32, 6
%53 = or i32 %52, %51
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = tail call i32 @fputc(i32 %57, i32* %0)
%59 = add nsw i32 %12, 3
br label %60
60: ; preds = %49, %31
%61 = phi i32 [ %59, %49 ], [ %48, %31 ]
br i1 %26, label %62, label %70
62: ; preds = %60
%63 = and i32 %32, 63
%64 = zext i32 %63 to i64
%65 = getelementptr inbounds [65 x i8], [65 x i8]* @.str, i64 0, i64 %64
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = tail call i32 @fputc(i32 %67, i32* %0)
%69 = add nsw i32 %61, 1
br label %70
70: ; preds = %60, %62
%71 = phi i32 [ %69, %62 ], [ %61, %60 ]
%72 = add nuw i64 %11, 3
%73 = trunc i64 %72 to i32
%74 = icmp slt i32 %73, %2
br i1 %74, label %10, label %7
75: ; preds = %7, %75
%76 = phi i32 [ %78, %75 ], [ %71, %7 ]
%77 = tail call i32 @fputc(i32 61, i32* %0)
%78 = add nsw i32 %76, 1
%79 = and i32 %78, 3
%80 = icmp eq i32 %79, 0
br i1 %80, label %81, label %75
81: ; preds = %75, %3, %7
ret void
}