#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 BUFSIZ;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int read_data(char *filename, char *name) {
  int size = 0, read_size = 0;
  FILE *fff;
  char *result, string[BUFSIZ];
  char read_name[BUFSIZ];
  fff = fopen(filename, "r");
  if (fff == NULL) {
    fprintf(stderr, "Error opening %s\n", filename);
    exit(1);
  }
  while (1) {
    result = fgets(string, BUFSIZ, fff);
    if (result == NULL)
      break;
    sscanf(string, "%s %*s %d", read_name, &read_size);
    if (!strcmp(name, read_name)) {
      fclose(fff);
      return read_size;
    }
  }
  fprintf(stderr, "Error!  %s not found in %s\n", name, filename);
  fclose(fff);
  return size;
}


x86 assembly (clang, -O0):
<read_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x60(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x40(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    121c <read_data+0xac>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1221 <read_data+0xb1>
jmp    1226 <read_data+0xb6>
mov    -0x60(%rbp),%rdi
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
mov    -0x28(%rbp),%rdx
call   1040 <fgets@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1250 <read_data+0xe0>
jmp    129e <read_data+0x12e>
mov    -0x58(%rbp),%rdx
mov    -0x60(%rbp),%rdi
lea    0xdb5(%rip),%rsi
lea    -0x20(%rbp),%rcx
call   1070 <sscanf@plt>
mov    -0x58(%rbp),%rsi
mov    -0x18(%rbp),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1299 <read_data+0x129>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    12d3 <read_data+0x163>
jmp    1221 <read_data+0xb1>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xd68(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_data>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rsp,-0x40(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    0x2e42(%rip),%rcx
mov    (%rcx),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    (%rcx),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe3d(%rip),%rsi
mov    %rdi,-0x38(%rbp)
call   1080 <fopen@plt>
test   %rax,%rax
je     1267 <read_data+0xf7>
mov    %rax,%r12
lea    -0x2c(%rbp),%r14
nopl   0x0(%rax)
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
mov    %r12,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     122a <read_data+0xba>
mov    %r13,%rdi
lea    0xe11(%rip),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1070 <sscanf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    11e0 <read_data+0x70>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    -0x2c(%rbp),%ebx
jmp    1252 <read_data+0xe2>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
xor    %ebx,%ebx
mov    %r15,%rdx
mov    -0x38(%rbp),%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    -0x40(%rbp),%rsp
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
lea    0xd8b(%rip),%rsi
mov    -0x38(%rbp),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"Error opening %s\0A\00"
@.str.2 = [10 x i8] c"%s %*s %d\00"
@.str.3 = [28 x i8] c"Error! %s not found in %s\0A\00"
define i32 @read_data(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
store i32 0, i32* %7
%14 = load i32, i32* @BUFSIZ
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %10
%17 = alloca i8, i64 %15
store i64 %15, i64* %11
%18 = load i32, i32* @BUFSIZ
%19 = zext i32 %18 to i64
%20 = alloca i8, i64 %19
store i64 %19, i64* %12
%21 = load i8*, i8** %4
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %8
%23 = load i32*, i32** %8
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %30
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %4
%28 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %2
br label %31
31: ; preds = %48, %30
br label %32
32: ; preds = %31
%33 = load i32, i32* @BUFSIZ
%34 = load i32*, i32** %8
%35 = call i8* @fgets(i8* %17, i32 %33, i32* %34)
store i8* %35, i8** %9
%36 = load i8*, i8** %9
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %39
38: ; preds = %32
br label %49
39: ; preds = %32
%40 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %20, i32* %7)
%41 = load i8*, i8** %5
%42 = call i32 @strcmp(i8* %41, i8* %20)
%43 = icmp ne i32 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %39
%45 = load i32*, i32** %8
%46 = call i32 @fclose(i32* %45)
%47 = load i32, i32* %7
store i32 %47, i32* %3
store i32 1, i32* %13
br label %57
48: ; preds = %39
br label %31
49: ; preds = %38
%50 = load i32, i32* @stderr
%51 = load i8*, i8** %5
%52 = load i8*, i8** %4
%53 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %51, i8* %52)
%54 = load i32*, i32** %8
%55 = call i32 @fclose(i32* %54)
%56 = load i32, i32* %6
store i32 %56, i32* %3
store i32 1, i32* %13
br label %57
57: ; preds = %49, %44
%58 = load i8*, i8** %10
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"Error opening %s\0A\00"
@.str.2 = [10 x i8] c"%s %*s %d\00"
@.str.3 = [28 x i8] c"Error! %s not found in %s\0A\00"
define i32 @read_data(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = load i32, i32* @BUFSIZ
%10 = zext i32 %9 to i64
%11 = alloca i8, i64 %10
%12 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %2, %22
%19 = load i32, i32* @BUFSIZ
%20 = call i8* @fgets(i8* %8, i32 %19, i32* %12)
%21 = icmp eq i8* %20, null
br i1 %21, label %29, label %22
22: ; preds = %18
%23 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %11, i32* %3)
%24 = call i32 @strcmp(i8* dereferenceable(1) %1, i8* %11)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %18
26: ; preds = %22
%27 = call i32 @fclose(i32* %12)
%28 = load i32, i32* %3
br label %33
29: ; preds = %18
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %0)
%32 = call i32 @fclose(i32* %12)
br label %33
33: ; preds = %29, %26
%34 = phi i32 [ 0, %29 ], [ %28, %26 ]
ret i32 %34
}