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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void write_cfile(const unsigned char *buf, off_t len, FILE *fp,
                 const char *name) {
  int i;
  fprintf(fp, "unsigned char %s[%ld] = {", name, len);
  for (i = 0; i < len; i++) {
    if ((i % 16) == 0) {
      fprintf(fp, "\n    ");
    }
    if (i == (len - 1)) {
      fprintf(fp, "0x%02x", buf[i]);
    } else if ((i % 16) == 15) {
      fprintf(fp, "0x%02x,", buf[i]);
    } else {
      fprintf(fp, "0x%02x, ", buf[i]);
    }
  }
  fprintf(fp, "\n};\n");
}


x86 assembly (clang, -O0):
<write_cfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xec7(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121a <write_cfile+0x10a>
mov    -0x24(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1179 <write_cfile+0x69>
mov    -0x18(%rbp),%rdi
lea    0xea8(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11ad <write_cfile+0x9d>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe7f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1207 <write_cfile+0xf7>
mov    -0x24(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
jne    11e4 <write_cfile+0xd4>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe4f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1202 <write_cfile+0xf2>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1207 <write_cfile+0xf7>
jmp    120c <write_cfile+0xfc>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1147 <write_cfile+0x37>
mov    -0x18(%rbp),%rdi
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_cfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %rdi,%r14
lea    0xec5(%rip),%rsi
mov    %rdx,%rdi
mov    %rcx,%rdx
mov    %r15d,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
test   %r15d,%r15d
jle    11d3 <write_cfile+0xb3>
lea    -0x1(%r15),%r12d
mov    %r15d,%r13d
lea    0xebe(%rip),%rbp
xor    %r15d,%r15d
jmp    118f <write_cfile+0x6f>
nopw   0x0(%rax,%rax,1)
lea    0xeb8(%rip),%rsi
movzbl (%r14,%r15,1),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%r15
cmp    %r15,%r13
je     11d3 <write_cfile+0xb3>
mov    %r15d,%eax
and    $0xf,%eax
je     11b0 <write_cfile+0x90>
mov    %rbp,%rsi
cmp    %r15,%r12
je     1177 <write_cfile+0x57>
lea    0xe81(%rip),%rsi
cmp    $0xf,%eax
jne    1170 <write_cfile+0x50>
jmp    1177 <write_cfile+0x57>
nopl   (%rax)
mov    $0x5,%esi
mov    $0x1,%edx
lea    0xe59(%rip),%rdi
mov    %rbx,%rcx
call   1040 <fwrite@plt>
mov    %rbp,%rsi
cmp    %r15,%r12
jne    1170 <write_cfile+0x50>
jmp    1177 <write_cfile+0x57>
lea    0xe5e(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fwrite@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"unsigned char %s[%ld] = {\00"
@.str.1 = [6 x i8] c"\0A \00"
@.str.2 = [7 x i8] c"0x%02x\00"
@.str.3 = [8 x i8] c"0x%02x,\00"
@.str.4 = [9 x i8] c"0x%02x, \00"
@.str.5 = [5 x i8] c"\0A};\0A\00"
define void @write_cfile(i8* %0, i32 %1, i32* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i8* %3, i8** %8
%10 = load i32*, i32** %7
%11 = load i8*, i8** %8
%12 = load i32, i32* %6
%13 = call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %12)
store i32 0, i32* %9
br label %14
14: ; preds = %63, %4
%15 = load i32, i32* %9
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %66
18: ; preds = %14
%19 = load i32, i32* %9
%20 = srem i32 %19, 16
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32*, i32** %7
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %22, %18
%26 = load i32, i32* %9
%27 = load i32, i32* %6
%28 = sub nsw i32 %27, 1
%29 = icmp eq i32 %26, %28
br i1 %29, label %30, label %39
30: ; preds = %25
%31 = load i32*, i32** %7
%32 = load i8*, i8** %5
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %37)
br label %62
39: ; preds = %25
%40 = load i32, i32* %9
%41 = srem i32 %40, 16
%42 = icmp eq i32 %41, 15
br i1 %42, label %43, label %52
43: ; preds = %39
%44 = load i32*, i32** %7
%45 = load i8*, i8** %5
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %50)
br label %61
52: ; preds = %39
%53 = load i32*, i32** %7
%54 = load i8*, i8** %5
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %52, %43
br label %62
62: ; preds = %61, %30
br label %63
63: ; preds = %62
%64 = load i32, i32* %9
%65 = add nsw i32 %64, 1
store i32 %65, i32* %9
br label %14
66: ; preds = %14
%67 = load i32*, i32** %7
%68 = call i32 (i32*, i8*, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"unsigned char %s[%ld] = {\00"
@.str.1 = [6 x i8] c"\0A \00"
@.str.2 = [7 x i8] c"0x%02x\00"
@.str.3 = [8 x i8] c"0x%02x,\00"
@.str.4 = [9 x i8] c"0x%02x, \00"
@.str.5 = [5 x i8] c"\0A};\0A\00"
define void @write_cfile(i8* nocapture %0, i32 %1, i32* nocapture %2, i8* %3) {
%5 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %1)
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %32
7: ; preds = %4
%8 = add nsw i32 %1, -1
%9 = zext i32 %8 to i64
%10 = zext i32 %1 to i64
br label %11
11: ; preds = %7, %24
%12 = phi i64 [ 0, %7 ], [ %30, %24 ]
%13 = trunc i64 %12 to i32
%14 = and i32 %13, 15
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = icmp eq i64 %12, %9
br i1 %17, label %24, label %21
18: ; preds = %11
%19 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 5, i64 1, i32* %2)
%20 = icmp eq i64 %12, %9
br i1 %20, label %24, label %23
21: ; preds = %16
%22 = icmp eq i32 %14, 15
br i1 %22, label %24, label %23
23: ; preds = %18, %21
br label %24
24: ; preds = %21, %16, %18, %23
%25 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), %23 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %18 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %16 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), %21 ]
%26 = getelementptr inbounds i8, i8* %0, i64 %12
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* %25, i32 %28)
%30 = add nuw nsw i64 %12, 1
%31 = icmp eq i64 %30, %10
br i1 %31, label %32, label %11
32: ; preds = %24, %4
%33 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i64 4, i64 1, i32* %2)
ret void
}