#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 *);
int /*<<< orphan*/ fwrite(TYPE_1__ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(TYPE_1__ *, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  FILE *fp;
  long count;
  char *names[3] = {"Tanaka", "Yamada", "Megumi"};
  struct record_table_t {
    int record_num;
    char name[20];
  } record_table;
  fp = fopen("test_3-2.dat", "wb");
  if (fp == NULL) {
    printf("\nFailed to open file!");
    return (-1);
  }
  for (count = 0; count < 3; count++) {
    memset(&record_table, 0x00, sizeof(record_table));
    record_table.record_num = count + 1;
    memcpy(record_table.name, names[count], strlen(names[count]));
    fwrite(&record_table, sizeof(record_table), 1, fp);
  }
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2c73(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2c70(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2c6d(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe67(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e1 <main+0x71>
lea    0xe55(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127d <main+0x10d>
movq   $0x0,-0x20(%rbp)
cmpq   $0x3,-0x20(%rbp)
jge    126d <main+0xfd>
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x58(%rbp)
lea    -0x58(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rax
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
call   1040 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
lea    -0x58(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x18,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11e9 <main+0x79>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xe92(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     128a <main+0x11a>
mov    %rax,%rbx
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r12
xor    %r14d,%r14d
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
movl   $0x1,0x8(%rsp)
lea    0xe3a(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    %r12,%rdi
mov    $0x18,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
movl   $0x2,0x8(%rsp)
lea    0xdf9(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    %r12,%rdi
mov    $0x18,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
movl   $0x3,0x8(%rsp)
lea    0xdb8(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    %r12,%rdi
mov    $0x18,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    129c <main+0x12c>
lea    0xd94(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.record_table_t = type { i32, [20 x i8] }
%struct.record_table_t.0 = type { i32, i8* }
@.str = [7 x i8] c"Tanaka\00"
@.str.1 = [7 x i8] c"Yamada\00"
@.str.2 = [7 x i8] c"Megumi\00"
@__const.main.names = [3 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [13 x i8] c"test_3-2.dat\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [22 x i8] c"\0AFailed to open file!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca [3 x i8*]
%9 = alloca %struct.record_table_t
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [3 x i8*]* %8 to i8*
%11 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 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* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %46
16: ; preds = %2
store i64 0, i64* %7
br label %17
17: ; preds = %40, %16
%18 = load i64, i64* %7
%19 = icmp slt i64 %18, 3
br i1 %19, label %20, label %43
20: ; preds = %17
%21 = bitcast %struct.record_table_t* %9 to %struct.record_table_t.0*
%22 = call i32 @memset(%struct.record_table_t.0* %21, i32 0, i32 24)
%23 = load i64, i64* %7
%24 = add nsw i64 %23, 1
%25 = trunc i64 %24 to i32
%26 = getelementptr inbounds %struct.record_table_t, %struct.record_table_t* %9, i32 0, i32 0
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.record_table_t, %struct.record_table_t* %9, i32 0, i32 1
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %27, i64 0, i64 0
%29 = load i64, i64* %7
%30 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 %29
%31 = load i8*, i8** %30
%32 = load i64, i64* %7
%33 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 %32
%34 = load i8*, i8** %33
%35 = call i32 @strlen(i8* %34)
%36 = call i32 @memcpy(i8* %28, i8* %31, i32 %35)
%37 = bitcast %struct.record_table_t* %9 to %struct.record_table_t.0*
%38 = load i32*, i32** %6
%39 = call i32 @fwrite(%struct.record_table_t.0* %37, i32 24, i32 1, i32* %38)
br label %40
40: ; preds = %20
%41 = load i64, i64* %7
%42 = add nsw i64 %41, 1
store i64 %42, i64* %7
br label %17
43: ; preds = %17
%44 = load i32*, i32** %6
%45 = call i32 @fclose(i32* %44)
store i32 0, i32* %3
br label %46
46: ; preds = %43, %14
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
%struct.record_table_t = type { i32, [20 x i8] }
%struct.record_table_t.0 = type { i32, i8* }
@.str = [7 x i8] c"Tanaka\00"
@.str.1 = [7 x i8] c"Yamada\00"
@.str.2 = [7 x i8] c"Megumi\00"
@.str.3 = [13 x i8] c"test_3-2.dat\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [22 x i8] c"\0AFailed to open file!\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 ([13 x i8], [13 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 %24, label %7
7: ; preds = %2
%8 = bitcast %struct.record_table_t* %3 to %struct.record_table_t.0*
%9 = getelementptr inbounds %struct.record_table_t, %struct.record_table_t* %3, i64 0, i32 0
%10 = getelementptr inbounds %struct.record_table_t, %struct.record_table_t* %3, i64 0, i32 1, i64 0
%11 = call i32 @memset(%struct.record_table_t.0* %8, i32 0, i32 24)
store i32 1, i32* %9
%12 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @memcpy(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @fwrite(%struct.record_table_t.0* %8, i32 24, i32 1, i32* %5)
%15 = call i32 @memset(%struct.record_table_t.0* %8, i32 0, i32 24)
store i32 2, i32* %9
%16 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @memcpy(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = call i32 @fwrite(%struct.record_table_t.0* %8, i32 24, i32 1, i32* %5)
%19 = call i32 @memset(%struct.record_table_t.0* %8, i32 0, i32 24)
store i32 3, i32* %9
%20 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @memcpy(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = call i32 @fwrite(%struct.record_table_t.0* %8, i32 24, i32 1, i32* %5)
%23 = call i32 @fclose(i32* %5)
br label %26
24: ; preds = %2
%25 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %7, %24
%27 = phi i32 [ -1, %24 ], [ 0, %7 ]
ret i32 %27
}