#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 u_int;
typedef int /*<<< orphan*/ u_char;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
char *ssh_malloc(int);
int ssh_uuencode(int /*<<< orphan*/ const *, int, char *, int);
void dump_base64(FILE *fp, const u_char *data, u_int len) {
  char *buf;
  int i, n;
  if (len > 65536) {
    fprintf(fp, "dump_base64: len > 65536\n");
    return;
  }
  buf = ssh_malloc(2 * len);
  n = ssh_uuencode(data, len, buf, 2 * len);
  for (i = 0; i < n; i++) {
    fprintf(fp, "%c", buf[i]);
    if (i % 70 == 69)
      fprintf(fp, "\n");
  }
  if (i % 70 != 69)
    fprintf(fp, "\n");
  free(buf);
}


x86 assembly (clang, -O0):
<dump_base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x10000,-0x14(%rbp)
jle    1177 <dump_base64+0x37>
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1238 <dump_base64+0xf8>
mov    -0x14(%rbp),%edi
shl    $0x1,%edi
call   1040 <ssh_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
call   1060 <ssh_uuencode@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1209 <dump_base64+0xc9>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    $0x46,%ecx
cltd
idiv   %ecx
cmp    $0x45,%edx
jne    11f6 <dump_base64+0xb6>
mov    -0x8(%rbp),%rdi
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11fb <dump_base64+0xbb>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a6 <dump_base64+0x66>
mov    -0x24(%rbp),%eax
mov    $0x46,%ecx
cltd
idiv   %ecx
cmp    $0x45,%edx
je     122f <dump_base64+0xef>
mov    -0x8(%rbp),%rdi
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_base64>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
cmp    $0x10001,%edx
jl     118d <dump_base64+0x3d>
lea    0xe93(%rip),%rdi
mov    $0x19,%esi
mov    $0x1,%edx
mov    %r13,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fwrite@plt>
mov    %edx,%ebp
mov    %rsi,%r15
lea    0x0(%rbp,%rbp,1),%r12d
mov    %r12d,%edi
call   1050 <ssh_malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    %ebp,%esi
mov    %rax,%rdx
mov    %r12d,%ecx
call   1060 <ssh_uuencode@plt>
test   %eax,%eax
jle    1224 <dump_base64+0xd4>
mov    %eax,0x4(%rsp)
mov    %eax,%ebp
xor    %ebx,%ebx
mov    $0xea0ea0eb,%r12d
jmp    11d9 <dump_base64+0x89>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     120e <dump_base64+0xbe>
mov    %ebx,%eax
shr    %eax
imul   %r12,%rax
shr    $0x25,%rax
imul   $0x46,%eax,%r15d
add    $0x45,%r15d
movsbl (%r14,%rbx,1),%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
cmp    %ebx,%r15d
jne    11d0 <dump_base64+0x80>
mov    $0xa,%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
jmp    11d0 <dump_base64+0x80>
imul   $0x8af8af8b,0x4(%rsp),%eax
8a
add    $0x8af8af89,%eax
ror    %eax
cmp    $0x3a83a83,%eax
jb     1231 <dump_base64+0xe1>
mov    $0xa,%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"dump_base64: len > 65536\0A\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @dump_base64(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = icmp sgt i32 %10, 65536
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = load i32*, i32** %4
%14 = call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %58
15: ; preds = %3
%16 = load i32, i32* %6
%17 = mul nsw i32 2, %16
%18 = call i8* @ssh_malloc(i32 %17)
store i8* %18, i8** %7
%19 = load i32*, i32** %5
%20 = load i32, i32* %6
%21 = load i8*, i8** %7
%22 = load i32, i32* %6
%23 = mul nsw i32 2, %22
%24 = call i32 @ssh_uuencode(i32* %19, i32 %20, i8* %21, i32 %23)
store i32 %24, i32* %9
store i32 0, i32* %8
br label %25
25: ; preds = %45, %15
%26 = load i32, i32* %8
%27 = load i32, i32* %9
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %48
29: ; preds = %25
%30 = load i32*, i32** %4
%31 = load i8*, i8** %7
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %8
%39 = srem i32 %38, 70
%40 = icmp eq i32 %39, 69
br i1 %40, label %41, label %44
41: ; preds = %29
%42 = load i32*, i32** %4
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %44
44: ; preds = %41, %29
br label %45
45: ; preds = %44
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %25
48: ; preds = %25
%49 = load i32, i32* %8
%50 = srem i32 %49, 70
%51 = icmp ne i32 %50, 69
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = load i32*, i32** %4
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %55
55: ; preds = %52, %48
%56 = load i8*, i8** %7
%57 = call i32 @free(i8* %56)
br label %58
58: ; preds = %55, %12
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"dump_base64: len > 65536\0A\00"
define void @dump_base64(i32* nocapture %0, i32* %1, i32 %2) {
%4 = icmp sgt i32 %2, 65536
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 25, i64 1, i32* %0)
br label %35
7: ; preds = %3
%8 = shl nsw i32 %2, 1
%9 = tail call i8* @ssh_malloc(i32 %8)
%10 = tail call i32 @ssh_uuencode(i32* %1, i32 %2, i8* %9, i32 %8)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %31
12: ; preds = %7
%13 = zext i32 %10 to i64
br label %14
14: ; preds = %12, %25
%15 = phi i64 [ 0, %12 ], [ %26, %25 ]
%16 = getelementptr inbounds i8, i8* %9, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = tail call i32 @fputc(i32 %18, i32* %0)
%20 = trunc i64 %15 to i32
%21 = urem i32 %20, 70
%22 = icmp eq i32 %21, 69
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = tail call i32 @fputc(i32 10, i32* %0)
br label %25
25: ; preds = %14, %23
%26 = add nuw nsw i64 %15, 1
%27 = icmp eq i64 %26, %13
br i1 %27, label %28, label %14
28: ; preds = %25
%29 = urem i32 %10, 70
%30 = icmp eq i32 %29, 69
br i1 %30, label %33, label %31
31: ; preds = %7, %28
%32 = tail call i32 @fputc(i32 10, i32* %0)
br label %33
33: ; preds = %31, %28
%34 = tail call i32 @free(i8* %9)
br label %35
35: ; preds = %33, %5
ret void
}