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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ translate_to_memory(unsigned char *, int *, char *, int);
int translate_file(unsigned char *memory, const char *file_input) {
  int index_mem = 0;
  int line_count = 0;
  char line[200];
  FILE *f;
  f = fopen(file_input, "r");
  if (f != NULL) {
    for (line_count = 0; fgets(line, sizeof(line), f) != NULL; line_count++) {
      if (line[0] != '\n' && line[0] != '#')
        translate_to_memory(memory, &index_mem, line, line_count);
    }
  } else {
    printf("No such file o archive with name %s\n", file_input);
    exit(1);
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<translate_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0xe8(%rbp)
cmpq   $0x0,-0xe8(%rbp)
je     121e <translate_file+0xbe>
movl   $0x0,-0x18(%rbp)
lea    -0xe0(%rbp),%rdi
mov    -0xe8(%rbp),%rdx
mov    $0xc8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1219 <translate_file+0xb9>
movsbl -0xe0(%rbp),%eax
cmp    $0xa,%eax
je     1206 <translate_file+0xa6>
movsbl -0xe0(%rbp),%eax
cmp    $0x23,%eax
je     1206 <translate_file+0xa6>
mov    -0x8(%rbp),%rdi
lea    -0xe0(%rbp),%rdx
mov    -0x18(%rbp),%ecx
lea    -0x14(%rbp),%rsi
call   1060 <translate_to_memory@plt>
jmp    120b <translate_file+0xab>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ad <translate_file+0x4d>
jmp    1238 <translate_file+0xd8>
mov    -0x10(%rbp),%rsi
lea    0xdd9(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0xe8(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<translate_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xe0,%rsp
mov    %rsi,%rbp
mov    %rdi,%r14
movl   $0x0,0xc(%rsp)
lea    0xe7c(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1211 <translate_file+0xb1>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0xc8,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11f7 <translate_file+0x97>
xor    %ebp,%ebp
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
jmp    11d8 <translate_file+0x78>
nopl   (%rax)
add    $0x1,%ebp
mov    %r15,%rdi
mov    $0xc8,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11f7 <translate_file+0x97>
movzbl 0x10(%rsp),%eax
cmp    $0xa,%al
je     11c0 <translate_file+0x60>
cmp    $0x23,%al
je     11c0 <translate_file+0x60>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %ebp,%ecx
call   1060 <translate_to_memory@plt>
jmp    11c0 <translate_file+0x60>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdea(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [37 x i8] c"No such file o archive with name %s\0A\00"
define i32 @translate_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [200 x i8]
%8 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %8
%11 = load i32*, i32** %8
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %39
13: ; preds = %2
store i32 0, i32* %6
br label %14
14: ; preds = %35, %13
%15 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%16 = load i32*, i32** %8
%17 = call i32* @fgets(i8* %15, i32 200, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %38
19: ; preds = %14
%20 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 10
br i1 %23, label %24, label %34
24: ; preds = %19
%25 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 35
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = load i8*, i8** %3
%31 = getelementptr inbounds [200 x i8], [200 x i8]* %7, i64 0, i64 0
%32 = load i32, i32* %6
%33 = call i32 @translate_to_memory(i8* %30, i32* %5, i8* %31, i32 %32)
br label %34
34: ; preds = %29, %24, %19
br label %35
35: ; preds = %34
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %14
38: ; preds = %14
br label %43
39: ; preds = %2
%40 = load i8*, i8** %4
%41 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %38
%44 = load i32*, i32** %8
%45 = call i32 @fclose(i32* %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [37 x i8] c"No such file o archive with name %s\0A\00"
define i32 @translate_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca [200 x i8]
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%7 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %21, label %9
9: ; preds = %2
%10 = call i32* @fgets(i8* %6, i32 200, i32* %7)
%11 = icmp eq i32* %10, null
br i1 %11, label %24, label %12
12: ; preds = %9, %17
%13 = phi i32 [ %18, %17 ], [ 0, %9 ]
%14 = load i8, i8* %6
switch i8 %14, label %15 [
i8 35, label %17
i8 10, label %17
]
15: ; preds = %12
%16 = call i32 @translate_to_memory(i8* %0, i32* %3, i8* %6, i32 %13)
br label %17
17: ; preds = %12, %12, %15
%18 = add nuw nsw i32 %13, 1
%19 = call i32* @fgets(i8* %6, i32 200, i32* %7)
%20 = icmp eq i32* %19, null
br i1 %20, label %24, label %12
21: ; preds = %2
%22 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %17, %9
%25 = call i32 @fclose(i32* %7)
ret i32 0
}