#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 */

/* Variables and functions */
size_t encode_base64(char *ostr, unsigned char *inbuf, int *inbuf_size,
                     int *line_len, int line_breaks, int cr) {
  static const unsigned char vec[] =
      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  static const char padding = '=';
  unsigned char out;
  size_t len = 0;
  out = (unsigned char)((*(inbuf + 0) & 0xFC) >> 2);
  *ostr++ = vec[out];
  out = (unsigned char)(((*(inbuf + 0) & 0x03) << 4) | (*(inbuf + 1) >> 4));
  *ostr++ = vec[out];
  out = (unsigned char)(((*(inbuf + 1) & 0x0F) << 2) | (*(inbuf + 2) >> 6));
  *ostr++ = (*inbuf_size > 1 ? vec[out] : padding);
  out = (unsigned char)(*(inbuf + 2) & 0x3F);
  *ostr++ = (*inbuf_size > 2 ? vec[out] : padding);
  line_len += 4;
  len = 4;
  if ((*line_len >= 76) && line_breaks) {
    if (cr)
      *ostr++ = '\r';
    *ostr++ = '\n';
    *line_len = 0;
    len++;
  }
  *inbuf_size = 0;
  return len;
}


x86 assembly (clang, -O0):
<encode_base64>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
and    $0xfc,%eax
sar    $0x2,%eax
mov    %al,-0x29(%rbp)
movzbl -0x29(%rbp),%eax
mov    %eax,%ecx
lea    0xebd(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
and    $0x3,%eax
shl    $0x4,%eax
mov    -0x10(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
sar    $0x4,%ecx
or     %ecx,%eax
mov    %al,-0x29(%rbp)
movzbl -0x29(%rbp),%eax
mov    %eax,%ecx
lea    0xe7f(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0xf,%eax
shl    $0x2,%eax
mov    -0x10(%rbp),%rcx
movzbl 0x2(%rcx),%ecx
sar    $0x6,%ecx
or     %ecx,%eax
mov    %al,-0x29(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x1,(%rax)
jle    11d9 <encode_base64+0xd9>
movzbl -0x29(%rbp),%eax
mov    %eax,%ecx
lea    0xe33(%rip),%rax
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x3c(%rbp)
jmp    11e6 <encode_base64+0xe6>
mov    $0x3d,%eax
mov    %eax,-0x3c(%rbp)
jmp    11e6 <encode_base64+0xe6>
mov    -0x3c(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0x3f,%eax
mov    %al,-0x29(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x2,(%rax)
jle    1230 <encode_base64+0x130>
movzbl -0x29(%rbp),%eax
mov    %eax,%ecx
lea    0xddc(%rip),%rax
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x40(%rbp)
jmp    123d <encode_base64+0x13d>
mov    $0x3d,%eax
mov    %eax,-0x40(%rbp)
jmp    123d <encode_base64+0x13d>
mov    -0x40(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x20(%rbp)
movq   $0x4,-0x38(%rbp)
mov    -0x20(%rbp),%rax
cmpl   $0x4c,(%rax)
jl     12c2 <encode_base64+0x1c2>
cmpl   $0x0,-0x24(%rbp)
je     12c2 <encode_base64+0x1c2>
cmpl   $0x0,-0x28(%rbp)
je     129a <encode_base64+0x19a>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0xd,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0xa,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x38(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_base64>:
push   %rbx
movzbl (%rsi),%eax
shr    $0x2,%rax
lea    0xef1(%rip),%r10
mov    (%rax,%r10,1),%al
mov    %al,(%rdi)
movzbl (%rsi),%r11d
shl    $0x4,%r11d
and    $0x30,%r11d
movzbl 0x1(%rsi),%eax
shr    $0x4,%rax
or     %r11,%rax
mov    (%r10,%rax,1),%al
mov    %al,0x1(%rdi)
mov    $0x3d,%r11b
cmpl   $0x2,(%rdx)
mov    $0x3d,%al
jl     1154 <encode_base64+0x54>
movzbl 0x1(%rsi),%eax
and    $0xf,%eax
movzbl 0x2(%rsi),%ebx
shr    $0x6,%rbx
lea    (%rbx,%rax,4),%rax
mov    (%r10,%rax,1),%al
mov    %al,0x2(%rdi)
cmpl   $0x3,(%rdx)
jl     1167 <encode_base64+0x67>
movzbl 0x2(%rsi),%eax
and    $0x3f,%eax
mov    (%rax,%r10,1),%r11b
mov    %r11b,0x3(%rdi)
mov    $0x4,%eax
test   %r8d,%r8d
je     119d <encode_base64+0x9d>
cmpl   $0x4c,0x10(%rcx)
jl     119d <encode_base64+0x9d>
test   %r9d,%r9d
je     118a <encode_base64+0x8a>
movb   $0xd,0x4(%rdi)
add    $0x5,%rdi
jmp    118e <encode_base64+0x8e>
add    $0x4,%rdi
movb   $0xa,(%rdi)
movl   $0x0,0x10(%rcx)
mov    $0x5,%eax
movl   $0x0,(%rdx)
pop    %rbx
ret

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

LLVM IR (-O2):
@encode_base64.vec = internal unnamed_addr constant [65 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\00"
define i64 @encode_base64(i8* nocapture writeonly %0, i8* nocapture %1, i32* nocapture %2, i32* nocapture %3, i32 %4, i32 %5) {
%7 = load i8, i8* %1
%8 = lshr i8 %7, 2
%9 = zext i8 %8 to i64
%10 = getelementptr inbounds [65 x i8], [65 x i8]* @encode_base64.vec, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %11, i8* %0
%13 = load i8, i8* %1
%14 = shl i8 %13, 4
%15 = and i8 %14, 48
%16 = getelementptr inbounds i8, i8* %1, i64 1
%17 = load i8, i8* %16
%18 = lshr i8 %17, 4
%19 = or i8 %15, %18
%20 = zext i8 %19 to i64
%21 = getelementptr inbounds [65 x i8], [65 x i8]* @encode_base64.vec, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %22, i8* %12
%24 = getelementptr inbounds i8, i8* %1, i64 2
%25 = load i32, i32* %2
%26 = icmp sgt i32 %25, 1
br i1 %26, label %27, label %37
27: ; preds = %6
%28 = load i8, i8* %16
%29 = shl i8 %28, 2
%30 = and i8 %29, 60
%31 = load i8, i8* %24
%32 = lshr i8 %31, 6
%33 = or i8 %30, %32
%34 = zext i8 %33 to i64
%35 = getelementptr inbounds [65 x i8], [65 x i8]* @encode_base64.vec, i64 0, i64 %34
%36 = load i8, i8* %35
br label %37
37: ; preds = %6, %27
%38 = phi i8 [ %36, %27 ], [ 61, %6 ]
%39 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %38, i8* %23
%40 = load i32, i32* %2
%41 = icmp sgt i32 %40, 2
br i1 %41, label %42, label %48
42: ; preds = %37
%43 = load i8, i8* %24
%44 = and i8 %43, 63
%45 = zext i8 %44 to i64
%46 = getelementptr inbounds [65 x i8], [65 x i8]* @encode_base64.vec, i64 0, i64 %45
%47 = load i8, i8* %46
br label %48
48: ; preds = %37, %42
%49 = phi i8 [ %47, %42 ], [ 61, %37 ]
%50 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %49, i8* %39
%51 = getelementptr inbounds i32, i32* %3, i64 4
%52 = load i32, i32* %51
%53 = icmp sgt i32 %52, 75
%54 = icmp ne i32 %4, 0
%55 = and i1 %54, %53
br i1 %55, label %56, label %62
56: ; preds = %48
%57 = icmp eq i32 %5, 0
br i1 %57, label %60, label %58
58: ; preds = %56
%59 = getelementptr inbounds i8, i8* %0, i64 5
store i8 13, i8* %50
br label %60
60: ; preds = %58, %56
%61 = phi i8* [ %59, %58 ], [ %50, %56 ]
store i8 10, i8* %61
store i32 0, i32* %51
br label %62
62: ; preds = %60, %48
%63 = phi i64 [ 5, %60 ], [ 4, %48 ]
store i32 0, i32* %2
ret i64 %63
}