#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 */
typedef struct record_table_t TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ record_table;
struct record_table_t {
  int record_num;
  char *name;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(TYPE_1__ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  struct record_table_t {
    int record_num;
    char name[20];
  } record_table;
  FILE *fp;
  char *names[3] = {"sir1", "sir2", "sir3"};
  fp = fopen("test_data.dat", "rb");
  if (fp == NULL) {
    printf("\nFailed to open file!");
    return -1;
  }
  while (fread(&record_table, sizeof(record_table), 1, fp) != 0) {
    printf("\nrecord_num  = %u, name = %s", record_table.record_num,
           record_table.name);
  }
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ca3(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0x2ca0(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0x2c9d(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe91(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11b3 <main+0x73>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <main+0xc7>
jmp    11b8 <main+0x78>
lea    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x18,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
je     11f7 <main+0xb7>
mov    -0x28(%rbp),%esi
lea    -0x28(%rbp),%rdx
add    $0x4,%rdx
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11b8 <main+0x78>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeae(%rip),%rdi
lea    0xeb5(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c6 <main+0x86>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x18,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11ba <main+0x7a>
lea    0x4(%rsp),%r14
lea    0xe9b(%rip),%r15
mov    %rsp,%r12
nop
mov    (%rsp),%esi
mov    %r15,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    $0x18,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    1190 <main+0x50>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11d9 <main+0x99>
lea    0xe44(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.record_table_t = type { i32, [20 x i8] }
%struct.record_table_t.0 = type { i32, i8* }
@.str = [5 x i8] c"sir1\00"
@.str.1 = [5 x i8] c"sir2\00"
@.str.2 = [5 x i8] c"sir3\00"
@__const.main.names = [3 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [14 x i8] c"test_data.dat\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [22 x i8] c"\0AFailed to open file!\00"
@.str.6 = [29 x i8] c"\0Arecord_num = %u, name = %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.record_table_t
%7 = alloca i32*
%8 = alloca [3 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [3 x i8*]* %8 to i8*
%10 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %30
15: ; preds = %2
br label %16
16: ; preds = %21, %15
%17 = bitcast %struct.record_table_t* %6 to %struct.record_table_t.0*
%18 = load i32*, i32** %7
%19 = call i64 @fread(%struct.record_table_t.0* %17, i32 24, i32 1, i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = getelementptr inbounds %struct.record_table_t, %struct.record_table_t* %6, i32 0, i32 0
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.record_table_t, %struct.record_table_t* %6, i32 0, i32 1
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %24, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %23, i8* %25)
br label %16
27: ; preds = %16
%28 = load i32*, i32** %7
%29 = call i32 @fclose(i32* %28)
store i32 0, i32* %3
br label %30
30: ; preds = %27, %13
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
%struct.record_table_t = type { i32, [20 x i8] }
%struct.record_table_t.0 = type { i32, i8* }
@.str.3 = [14 x i8] c"test_data.dat\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [22 x i8] c"\0AFailed to open file!\00"
@.str.6 = [29 x i8] c"\0Arecord_num = %u, name = %s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.record_table_t
%4 = bitcast %struct.record_table_t* %3 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %14, label %7
7: ; preds = %2
%8 = bitcast %struct.record_table_t* %3 to %struct.record_table_t.0*
%9 = call i64 @fread(%struct.record_table_t.0* %8, i32 24, i32 1, i32* %5)
%10 = icmp eq i64 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %7
%12 = getelementptr inbounds %struct.record_table_t, %struct.record_table_t* %3, i64 0, i32 0
%13 = getelementptr inbounds %struct.record_table_t, %struct.record_table_t* %3, i64 0, i32 1, i64 0
br label %16
14: ; preds = %2
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %23
16: ; preds = %11, %16
%17 = load i32, i32* %12
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i32 %17, i8* %13)
%19 = call i64 @fread(%struct.record_table_t.0* %8, i32 24, i32 1, i32* %5)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %16
21: ; preds = %16, %7
%22 = call i32 @fclose(i32* %5)
br label %23
23: ; preds = %21, %14
%24 = phi i32 [ -1, %14 ], [ 0, %21 ]
ret i32 %24
}