#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 fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
void txt2c(char *sym, FILE *fp) {
  unsigned char buf[12];
  int i;
  int sz = 0;
  printf("unsigned char %s[] = {\n", sym);
  while (true) {
    sz = fread(buf, sizeof(unsigned char), 12, fp);
    if (sz == 0)
      break;
    printf("\t");
    for (i = 0; i < sz; i++)
      printf("0x%02x, ", buf[i]);
    printf("\n");
  }
  printf("\t0x00\n};\n");
}


x86 assembly (clang, -O0):
<txt2c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1c(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0xc,%edx
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1172 <txt2c+0x52>
jmp    11cb <txt2c+0xab>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11b8 <txt2c+0x98>
movslq -0x20(%rbp),%rax
movzbl -0x1c(%rbp,%rax,1),%esi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1187 <txt2c+0x67>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1149 <txt2c+0x29>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<txt2c>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
lea    0xea7(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0xc,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
test   %eax,%eax
je     11ea <txt2c+0xaa>
mov    %eax,%ebp
lea    0xe94(%rip),%r12
lea    0x4(%rsp),%r15
jmp    11b5 <txt2c+0x75>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0xc,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11ea <txt2c+0xaa>
mov    $0x9,%edi
call   1030 <putchar@plt>
test   %ebp,%ebp
jle    1190 <txt2c+0x50>
mov    %ebp,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl 0x4(%rsp,%rbx,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11d0 <txt2c+0x90>
jmp    1190 <txt2c+0x50>
lea    0xe30(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"unsigned char %s[] = {\0A\00"
@.str.1 = [2 x i8] c"\09\00"
@.str.2 = [9 x i8] c"0x%02x, \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [10 x i8] c"\090x00\0A};\0A\00"
define void @txt2c(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [12 x i8]
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 0, i32* %7
%8 = load i8*, i8** %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %2, %33
%11 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
%12 = load i32*, i32** %4
%13 = call i32 @fread(i8* %11, i32 1, i32 12, i32* %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10
br label %35
17: ; preds = %10
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
br label %19
19: ; preds = %30, %17
%20 = load i32, i32* %6
%21 = load i32, i32* %7
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %23
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %19
33: ; preds = %19
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %10
35: ; preds = %16
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"unsigned char %s[] = {\0A\00"
@.str.2 = [9 x i8] c"0x%02x, \00"
@str = [9 x i8] c"\090x00\0A};\00"
define void @txt2c(i8* %0, i32* nocapture %1) {
%3 = alloca [12 x i8]
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = call i32 @fread(i8* %4, i32 1, i32 12, i32* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %26, label %8
8: ; preds = %2, %22
%9 = phi i32 [ %24, %22 ], [ %6, %2 ]
%10 = tail call i32 @putchar(i32 9)
%11 = icmp sgt i32 %9, 0
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = zext i32 %9 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ 0, %12 ], [ %20, %14 ]
%16 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = add nuw nsw i64 %15, 1
%21 = icmp eq i64 %20, %13
br i1 %21, label %22, label %14
22: ; preds = %14, %8
%23 = tail call i32 @putchar(i32 10)
%24 = call i32 @fread(i8* %4, i32 1, i32 12, i32* %1)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %8
26: ; preds = %22, %2
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
ret void
}