#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*/ *fopen(char const *, char *);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int label2array(const char *variable, const char *filename) {
  FILE *in;
  if ((in = fopen(filename, "r")) == NULL)
    return -1;
  printf("const char %s[] = \"", variable);
  unsigned char c;
  while (fread(&c, 1, 1, in) > 0)
    switch (c) {
    case '\t':
    case '\n':
      break;
    case '"':
      printf("\\\"");
      break;
      ;
    default:
      printf("%c", c);
    }
  printf("\";\n");
  return 0;
}


x86 assembly (clang, -O0):
<label2array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    116a <label2array+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <label2array+0xd7>
mov    -0x10(%rbp),%rsi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rcx
lea    -0x21(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%rax
jle    11f2 <label2array+0xc2>
movzbl -0x21(%rbp),%eax
mov    %eax,-0x28(%rbp)
add    $0xfffffff7,%eax
sub    $0x2,%eax
jb     11c3 <label2array+0x93>
jmp    11b2 <label2array+0x82>
mov    -0x28(%rbp),%eax
sub    $0x22,%eax
je     11c8 <label2array+0x98>
jmp    11db <label2array+0xab>
jmp    11ed <label2array+0xbd>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ed <label2array+0xbd>
movzbl -0x21(%rbp),%esi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    117c <label2array+0x4c>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<label2array>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%rbp
lea    0xe9c(%rip),%rsi
mov    %rax,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     120d <label2array+0xbd>
mov    %rax,%rbx
lea    0xe83(%rip),%rdi
xor    %r14d,%r14d
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
test   %rax,%rax
jle    11ff <label2array+0xaf>
lea    0x7(%rsp),%rbp
lea    0xe62(%rip),%r15
jmp    11e2 <label2array+0x92>
cs nopw 0x0(%rax,%rax,1)
movzbl %al,%edi
call   1030 <putchar@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
test   %rax,%rax
jle    11ff <label2array+0xaf>
movzbl 0x7(%rsp),%eax
lea    -0x9(%rax),%ecx
cmp    $0x2,%cl
jb     11c8 <label2array+0x78>
cmp    $0x22,%al
jne    11c0 <label2array+0x70>
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11c8 <label2array+0x78>
lea    0xe13(%rip),%rdi
call   1040 <puts@plt>
jmp    1213 <label2array+0xc3>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [20 x i8] c"const char %s[] = \22\00"
@.str.2 = [3 x i8] c"\\\22\00"
@str = [3 x i8] c"\22;\00"
define i32 @label2array(i8* %0, i8* nocapture %1) {
%3 = alloca i8
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %22, label %6
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = call i64 @fread(i8* %3, i32 1, i32 1, i32* %4)
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %6, %17
%11 = load i8, i8* %3
switch i8 %11, label %14 [
i8 9, label %17
i8 10, label %17
i8 34, label %12
]
12: ; preds = %10
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %17
14: ; preds = %10
%15 = zext i8 %11 to i32
%16 = tail call i32 @putchar(i32 %15)
br label %17
17: ; preds = %10, %10, %14, %12
%18 = call i64 @fread(i8* %3, i32 1, i32 1, i32* %4)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %10, label %20
20: ; preds = %17, %6
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %2, %20
%23 = phi i32 [ 0, %20 ], [ -1, %2 ]
ret i32 %23
}