#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fwrite(unsigned char const *, int, int const,
                          int /*<<< orphan*/ *);
int write_b64_file(const char *header, const char *fname,
                   const unsigned char *data, const int data_size) {
  int i;
  FILE *out = fopen(fname, "wb");
  if (!out) {
    return -2;
  }
  fprintf(out, "%s\r\n", header);
  for (i = 0; i < data_size / 76; i++) {
    fwrite(data + 76 * i * sizeof(unsigned char), 1, 76, out);
    fprintf(out, "\r\n");
  }
  fwrite(data + 76 * (data_size / 76) * sizeof(unsigned char), 1,
         (data_size % 76), out);
  fclose(out);
  return 1;
}


x86 assembly (clang, -O0):
<write_b64_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1182 <write_b64_file+0x42>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1245 <write_b64_file+0x105>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x4c,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    1201 <write_b64_file+0xc1>
mov    -0x20(%rbp),%rdi
imul   $0x4c,-0x28(%rbp),%eax
cltq
shl    $0x0,%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4c,%edx
call   1060 <fwrite@plt>
mov    -0x30(%rbp),%rdi
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    119f <write_b64_file+0x5f>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%eax
mov    $0x4c,%ecx
cltd
idiv   %ecx
imul   $0x4c,%eax,%eax
cltq
shl    $0x0,%rax
add    %rax,%rdi
mov    -0x24(%rbp),%eax
mov    $0x4c,%ecx
cltd
idiv   %ecx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_b64_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rsi,%rax
mov    %rdi,%rbp
lea    0xea2(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     121e <write_b64_file+0xde>
mov    %rax,%rbx
lea    0xe8a(%rip),%rsi
mov    %rax,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
movslq %r15d,%rcx
imul   $0x6bca1af3,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rax
add    %edx,%eax
imul   $0x4c,%eax,%edx
mov    %ecx,%r15d
mov    %edx,0x4(%rsp)
sub    %edx,%r15d
cmp    $0x4c,%ecx
jl     11f4 <write_b64_file+0xb4>
mov    %eax,%r13d
lea    0xe4c(%rip),%r12
mov    %r14,%rbp
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x4c,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rdi
mov    %rbx,%rcx
call   1060 <fwrite@plt>
add    $0x4c,%rbp
add    $0xffffffffffffffff,%r13
jne    11c0 <write_b64_file+0x80>
movslq 0x4(%rsp),%rax
add    %rax,%r14
mov    $0x1,%ebp
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1223 <write_b64_file+0xe3>
mov    $0xfffffffe,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [5 x i8] c"%s\0D\0A\00"
@.str.2 = [3 x i8] c"\0D\0A\00"
define i32 @write_b64_file(i8* %0, i8* nocapture %1, i8* nocapture %2, i32 %3) {
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %28, label %7
7: ; preds = %4
%8 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = sdiv i32 %3, 76
%10 = srem i32 %3, 76
%11 = icmp sgt i32 %3, 75
br i1 %11, label %12, label %22
12: ; preds = %7
%13 = zext i32 %9 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ 0, %12 ], [ %20, %14 ]
%16 = mul nuw nsw i64 %15, 76
%17 = getelementptr inbounds i8, i8* %2, i64 %16
%18 = tail call i32 @fwrite(i8* %17, i32 1, i32 76, i32* %5)
%19 = tail call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 2, i64 1, i32* %5)
%20 = add nuw nsw i64 %15, 1
%21 = icmp eq i64 %20, %13
br i1 %21, label %22, label %14
22: ; preds = %14, %7
%23 = mul nsw i32 %9, 76
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %2, i64 %24
%26 = tail call i32 @fwrite(i8* %25, i32 1, i32 %10, i32* %5)
%27 = tail call i32 @fclose(i32* %5)
br label %28
28: ; preds = %4, %22
%29 = phi i32 [ 1, %22 ], [ -2, %4 ]
ret i32 %29
}