#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*/ network_convbase64_8x3_to_6x4(char const *, char *);
int strlen(char const *);
void network_base64encode(const char *from, char *to) {
  const char *f;
  char *t;
  int from_len;
  from_len = strlen(from);
  f = from;
  t = to;
  while (from_len >= 3) {
    network_convbase64_8x3_to_6x4(f, t);
    f += 3 * sizeof(*f);
    t += 4 * sizeof(*t);
    from_len -= 3;
  }
  if (from_len > 0) {
    char rest[3] = {0, 0, 0};
    switch (from_len) {
    case 1:
      rest[0] = f[0];
      network_convbase64_8x3_to_6x4(rest, t);
      t[2] = t[3] = '=';
      break;
    case 2:
      rest[0] = f[0];
      rest[1] = f[1];
      network_convbase64_8x3_to_6x4(rest, t);
      t[3] = '=';
      break;
    }
    t[4] = 0;
  }
}


x86 assembly (clang, -O0):
<network_base64encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x3,-0x24(%rbp)
jl     1189 <network_base64encode+0x69>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <network_convbase64_8x3_to_6x4@plt>
mov    -0x18(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0x24(%rbp)
jmp    114c <network_base64encode+0x2c>
cmpl   $0x0,-0x24(%rbp)
jle    121d <network_base64encode+0xfd>
movb   $0x0,-0x26(%rbp)
movw   $0x0,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x1,%eax
je     11c2 <network_base64encode+0xa2>
jmp    11b1 <network_base64encode+0x91>
mov    -0x2c(%rbp),%eax
sub    $0x2,%eax
je     11ed <network_base64encode+0xcd>
jmp    1215 <network_base64encode+0xf5>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <network_convbase64_8x3_to_6x4@plt>
mov    -0x20(%rbp),%rax
movb   $0x3d,0x3(%rax)
mov    -0x20(%rbp),%rax
movb   $0x3d,0x2(%rax)
jmp    1215 <network_base64encode+0xf5>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x27(%rbp)
lea    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <network_convbase64_8x3_to_6x4@plt>
mov    -0x20(%rbp),%rax
movb   $0x3d,0x3(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,0x4(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<network_base64encode>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%ebx
cmp    $0x3,%eax
jl     1163 <network_base64encode+0x43>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <network_convbase64_8x3_to_6x4@plt>
add    $0x3,%r15
add    $0x4,%r14
lea    -0x3(%rbx),%eax
cmp    $0x5,%ebx
mov    %eax,%ebx
ja     1140 <network_base64encode+0x20>
test   %eax,%eax
jg     1169 <network_base64encode+0x49>
jmp    11ca <network_base64encode+0xaa>
mov    %ebx,%eax
test   %eax,%eax
jle    11ca <network_base64encode+0xaa>
movb   $0x0,0xe(%rsp)
movw   $0x0,0xc(%rsp)
cmp    $0x2,%eax
je     119f <network_base64encode+0x7f>
cmp    $0x1,%eax
jne    11c5 <network_base64encode+0xa5>
mov    (%r15),%al
mov    %al,0xc(%rsp)
lea    0xc(%rsp),%rdi
mov    %r14,%rsi
call   1040 <network_convbase64_8x3_to_6x4@plt>
movb   $0x3d,0x3(%r14)
mov    $0x2,%eax
jmp    11c0 <network_base64encode+0xa0>
mov    (%r15),%al
mov    %al,0xc(%rsp)
mov    0x1(%r15),%al
mov    %al,0xd(%rsp)
lea    0xc(%rsp),%rdi
mov    %r14,%rsi
call   1040 <network_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 @network_base64encode(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [3 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %7
%11 = load i8*, i8** %3
store i8* %11, i8** %5
%12 = load i8*, i8** %4
store i8* %12, i8** %6
br label %13
13: ; preds = %16, %2
%14 = load i32, i32* %7
%15 = icmp sge i32 %14, 3
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i8*, i8** %5
%18 = load i8*, i8** %6
%19 = call i32 @network_convbase64_8x3_to_6x4(i8* %17, i8* %18)
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 3
store i8* %21, i8** %5
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i64 4
store i8* %23, i8** %6
%24 = load i32, i32* %7
%25 = sub nsw i32 %24, 3
store i32 %25, i32* %7
br label %13
26: ; preds = %13
%27 = load i32, i32* %7
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %61
29: ; preds = %26
%30 = bitcast [3 x i8]* %8 to i8*
%31 = load i32, i32* %7
switch i32 %31, label %58 [
i32 1, label %32
i32 2, label %44
]
32: ; preds = %29
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
store i8 %35, i8* %36
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%38 = load i8*, i8** %6
%39 = call i32 @network_convbase64_8x3_to_6x4(i8* %37, i8* %38)
%40 = load i8*, i8** %6
%41 = getelementptr inbounds i8, i8* %40, i64 3
store i8 61, i8* %41
%42 = load i8*, i8** %6
%43 = getelementptr inbounds i8, i8* %42, i64 2
store i8 61, i8* %43
br label %58
44: ; preds = %29
%45 = load i8*, i8** %5
%46 = getelementptr inbounds i8, i8* %45, i64 0
%47 = load i8, i8* %46
%48 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
store i8 %47, i8* %48
%49 = load i8*, i8** %5
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = load i8, i8* %50
%52 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 1
store i8 %51, i8* %52
%53 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%54 = load i8*, i8** %6
%55 = call i32 @network_convbase64_8x3_to_6x4(i8* %53, i8* %54)
%56 = load i8*, i8** %6
%57 = getelementptr inbounds i8, i8* %56, i64 3
store i8 61, i8* %57
br label %58
58: ; preds = %29, %44, %32
%59 = load i8*, i8** %6
%60 = getelementptr inbounds i8, i8* %59, i64 4
store i8 0, i8* %60
br label %61
61: ; preds = %58, %26
ret void
}

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