#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int htoi(char *);
int /*<<< orphan*/ perror(char *);
int main(int argc, char *argv[]) {
  FILE *in, *out;
  in = fopen("input.dat", "r");
  if (in == NULL) {
    perror("input.dat");
    return 1;
  }
  out = fopen("output.dat", "w");
  if (out == NULL) {
    perror("output.dat");
    return 1;
  }
  char str[128];
  int n;
  while (fscanf(in, "%s", str) != EOF) {
    n = htoi(str);
    fprintf(out, "%x\n", n);
  }
  fclose(in);
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe80(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b3 <main+0x53>
lea    0xe5e(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    125f <main+0xff>
lea    0xe52(%rip),%rdi
lea    0xe56(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ed <main+0x8d>
lea    0xe30(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    125f <main+0xff>
jmp    11f2 <main+0x92>
mov    -0x18(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    0xe15(%rip),%rsi
call   1040 <fscanf@plt>
mov    0x2dd8(%rip),%rcx
cmp    (%rcx),%rax
je     1246 <main+0xe6>
lea    -0xa0(%rbp),%rdi
call   1060 <htoi@plt>
mov    %eax,-0xa4(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0xa4(%rbp),%edx
lea    0xde0(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11f2 <main+0x92>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
lea    0xe88(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     122d <main+0xcd>
mov    %rax,%r14
lea    0xe75(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1236 <main+0xd6>
mov    %rax,%r15
lea    0xe63(%rip),%rsi
mov    %rsp,%rdx
mov    %r14,%rdi
call   1040 <fscanf@plt>
mov    0x2e20(%rip),%rbp
cmp    0x0(%rbp),%rax
je     1209 <main+0xa9>
mov    %rsp,%rbx
lea    0xe44(%rip),%r12
lea    0xe3a(%rip),%r13
nop
mov    %rbx,%rdi
call   1060 <htoi@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1040 <fscanf@plt>
cmp    0x0(%rbp),%rax
jne    11e0 <main+0x80>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdcc(%rip),%rdi
jmp    123d <main+0xdd>
lea    0xdcf(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
jmp    121b <main+0xbb>

LLVM IR (-O0):
@.str = [10 x i8] c"input.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.dat\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.5 = [4 x i8] c"%x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [128 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %39
15: ; preds = %2
%16 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %39
21: ; preds = %15
br label %22
22: ; preds = %28, %21
%23 = load i32*, i32** %6
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%25 = call i64 @fscanf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%26 = load i64, i64* @EOF
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %34
28: ; preds = %22
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%30 = call i32 @htoi(i8* %29)
store i32 %30, i32* %9
%31 = load i32*, i32** %7
%32 = load i32, i32* %9
%33 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %32)
br label %22
34: ; preds = %22
%35 = load i32*, i32** %6
%36 = call i32 @fclose(i32* %35)
%37 = load i32*, i32** %7
%38 = call i32 @fclose(i32* %37)
store i32 0, i32* %3
br label %39
39: ; preds = %34, %19, %13
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.dat\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.5 = [4 x i8] c"%x\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %27
8: ; preds = %2
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %27
13: ; preds = %8
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%15 = call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %14)
%16 = load i64, i64* @EOF
%17 = icmp eq i64 %15, %16
br i1 %17, label %24, label %18
18: ; preds = %13, %18
%19 = call i32 @htoi(i8* %14)
%20 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%21 = call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %14)
%22 = load i64, i64* @EOF
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %18
24: ; preds = %18, %13
%25 = call i32 @fclose(i32* %4)
%26 = call i32 @fclose(i32* %9)
br label %27
27: ; preds = %24, %11, %6
%28 = phi i32 [ 1, %6 ], [ 1, %11 ], [ 0, %24 ]
ret i32 %28
}