#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 */
int /*<<< orphan*/ string_convbase64_8x3_to_6x4(char const *, char *);
void string_encode_base64(const char *from, int length, char *to) {
  const char *ptr_from;
  char *ptr_to;
  ptr_from = from;
  ptr_to = to;
  while (length >= 3) {
    string_convbase64_8x3_to_6x4(ptr_from, ptr_to);
    ptr_from += 3 * sizeof(*ptr_from);
    ptr_to += 4 * sizeof(*ptr_to);
    length -= 3;
  }
  if (length > 0) {
    char rest[3] = {0, 0, 0};
    switch (length) {
    case 1:
      rest[0] = ptr_from[0];
      string_convbase64_8x3_to_6x4(rest, ptr_to);
      ptr_to[2] = ptr_to[3] = '=';
      break;
    case 2:
      rest[0] = ptr_from[0];
      rest[1] = ptr_from[1];
      string_convbase64_8x3_to_6x4(rest, ptr_to);
      ptr_to[3] = '=';
      break;
    }
    ptr_to[4] = 0;
  } else
    ptr_to[0] = '\0';
}


x86 assembly (clang, -O0):
<string_encode_base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x3,-0xc(%rbp)
jl     1170 <string_encode_base64+0x60>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <string_convbase64_8x3_to_6x4@plt>
mov    -0x20(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0xc(%rbp)
jmp    1133 <string_encode_base64+0x23>
cmpl   $0x0,-0xc(%rbp)
jle    1209 <string_encode_base64+0xf9>
movb   $0x0,-0x2a(%rbp)
movw   $0x0,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x1,%eax
je     11a9 <string_encode_base64+0x99>
jmp    1198 <string_encode_base64+0x88>
mov    -0x30(%rbp),%eax
sub    $0x2,%eax
je     11d4 <string_encode_base64+0xc4>
jmp    11fc <string_encode_base64+0xec>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x2c(%rbp)
lea    -0x2c(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <string_convbase64_8x3_to_6x4@plt>
mov    -0x28(%rbp),%rax
movb   $0x3d,0x3(%rax)
mov    -0x28(%rbp),%rax
movb   $0x3d,0x2(%rax)
jmp    11fc <string_encode_base64+0xec>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x2b(%rbp)
lea    -0x2c(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <string_convbase64_8x3_to_6x4@plt>
mov    -0x28(%rbp),%rax
movb   $0x3d,0x3(%rax)
mov    -0x28(%rbp),%rax
movb   $0x0,0x4(%rax)
jmp    1210 <string_encode_base64+0x100>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_encode_base64>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rdi,%r15
cmp    $0x3,%esi
jl     1187 <string_encode_base64+0x77>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <string_convbase64_8x3_to_6x4@plt>
add    $0x3,%r15
add    $0x4,%r14
lea    -0x3(%rbx),%eax
cmp    $0x5,%ebx
mov    %eax,%ebx
ja     1130 <string_encode_base64+0x20>
test   %eax,%eax
jle    118d <string_encode_base64+0x7d>
movb   $0x0,0xe(%rsp)
movw   $0x0,0xc(%rsp)
cmp    $0x2,%eax
je     1193 <string_encode_base64+0x83>
cmp    $0x1,%eax
jne    11b9 <string_encode_base64+0xa9>
mov    (%r15),%al
mov    %al,0xc(%rsp)
lea    0xc(%rsp),%rdi
mov    %r14,%rsi
call   1030 <string_convbase64_8x3_to_6x4@plt>
movb   $0x3d,0x3(%r14)
mov    $0x2,%eax
jmp    11b4 <string_encode_base64+0xa4>
mov    %ebx,%eax
test   %eax,%eax
jg     1151 <string_encode_base64+0x41>
movb   $0x0,(%r14)
jmp    11be <string_encode_base64+0xae>
mov    (%r15),%al
mov    %al,0xc(%rsp)
mov    0x1(%r15),%al
mov    %al,0xd(%rsp)
lea    0xc(%rsp),%rdi
mov    %r14,%rsi
call   1030 <string_convbase64_8x3_to_6x4@plt>
mov    $0x3,%eax
movb   $0x3d,(%r14,%rax,1)
movb   $0x0,0x4(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @string_encode_base64(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [3 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = load i8*, i8** %4
store i8* %10, i8** %7
%11 = load i8*, i8** %6
store i8* %11, i8** %8
br label %12
12: ; preds = %15, %3
%13 = load i32, i32* %5
%14 = icmp sge i32 %13, 3
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = load i8*, i8** %7
%17 = load i8*, i8** %8
%18 = call i32 @string_convbase64_8x3_to_6x4(i8* %16, i8* %17)
%19 = load i8*, i8** %7
%20 = getelementptr inbounds i8, i8* %19, i64 3
store i8* %20, i8** %7
%21 = load i8*, i8** %8
%22 = getelementptr inbounds i8, i8* %21, i64 4
store i8* %22, i8** %8
%23 = load i32, i32* %5
%24 = sub nsw i32 %23, 3
store i32 %24, i32* %5
br label %12
25: ; preds = %12
%26 = load i32, i32* %5
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %60
28: ; preds = %25
%29 = bitcast [3 x i8]* %9 to i8*
%30 = load i32, i32* %5
switch i32 %30, label %57 [
i32 1, label %31
i32 2, label %43
]
31: ; preds = %28
%32 = load i8*, i8** %7
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
store i8 %34, i8* %35
%36 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%37 = load i8*, i8** %8
%38 = call i32 @string_convbase64_8x3_to_6x4(i8* %36, i8* %37)
%39 = load i8*, i8** %8
%40 = getelementptr inbounds i8, i8* %39, i64 3
store i8 61, i8* %40
%41 = load i8*, i8** %8
%42 = getelementptr inbounds i8, i8* %41, i64 2
store i8 61, i8* %42
br label %57
43: ; preds = %28
%44 = load i8*, i8** %7
%45 = getelementptr inbounds i8, i8* %44, i64 0
%46 = load i8, i8* %45
%47 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
store i8 %46, i8* %47
%48 = load i8*, i8** %7
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = load i8, i8* %49
%51 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 1
store i8 %50, i8* %51
%52 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%53 = load i8*, i8** %8
%54 = call i32 @string_convbase64_8x3_to_6x4(i8* %52, i8* %53)
%55 = load i8*, i8** %8
%56 = getelementptr inbounds i8, i8* %55, i64 3
store i8 61, i8* %56
br label %57
57: ; preds = %28, %43, %31
%58 = load i8*, i8** %8
%59 = getelementptr inbounds i8, i8* %58, i64 4
store i8 0, i8* %59
br label %63
60: ; preds = %25
%61 = load i8*, i8** %8
%62 = getelementptr inbounds i8, i8* %61, i64 0
store i8 0, i8* %62
br label %63
63: ; preds = %60, %57
ret void
}

LLVM IR (-O2):
define void @string_encode_base64(i8* %0, i32 %1, i8* %2) {
%4 = alloca [3 x i8]
%5 = icmp sgt i32 %1, 2
br i1 %5, label %6, label %15
6: ; preds = %3, %6
%7 = phi i8* [ %12, %6 ], [ %2, %3 ]
%8 = phi i8* [ %11, %6 ], [ %0, %3 ]
%9 = phi i32 [ %13, %6 ], [ %1, %3 ]
%10 = tail call i32 @string_convbase64_8x3_to_6x4(i8* %8, i8* %7)
%11 = getelementptr inbounds i8, i8* %8, i64 3
%12 = getelementptr inbounds i8, i8* %7, i64 4
%13 = add nsw i32 %9, -3
%14 = icmp ugt i32 %9, 5
br i1 %14, label %6, label %15
15: ; preds = %6, %3
%16 = phi i32 [ %1, %3 ], [ %13, %6 ]
%17 = phi i8* [ %0, %3 ], [ %11, %6 ]
%18 = phi i8* [ %2, %3 ], [ %12, %6 ]
%19 = icmp sgt i32 %16, 0
br i1 %19, label %20, label %37
20: ; preds = %15
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
switch i32 %16, label %35 [
i32 1, label %22
i32 2, label %26
]
22: ; preds = %20
%23 = load i8, i8* %17
store i8 %23, i8* %21
%24 = call i32 @string_convbase64_8x3_to_6x4(i8* %21, i8* %18)
%25 = getelementptr inbounds i8, i8* %18, i64 3
store i8 61, i8* %25
br label %32
26: ; preds = %20
%27 = load i8, i8* %17
store i8 %27, i8* %21
%28 = getelementptr inbounds i8, i8* %17, i64 1
%29 = load i8, i8* %28
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
store i8 %29, i8* %30
%31 = call i32 @string_convbase64_8x3_to_6x4(i8* %21, i8* %18)
br label %32
32: ; preds = %22, %26
%33 = phi i64 [ 3, %26 ], [ 2, %22 ]
%34 = getelementptr inbounds i8, i8* %18, i64 %33
store i8 61, i8* %34
br label %35
35: ; preds = %32, %20
%36 = getelementptr inbounds i8, i8* %18, i64 4
store i8 0, i8* %36
br label %38
37: ; preds = %15
store i8 0, i8* %18
br label %38
38: ; preds = %37, %35
ret void
}