#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 pirate TYPE_1__;

/* Type definitions */
struct pirate {
  char *name;
  unsigned long booty;
  unsigned int beard_len;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(TYPE_1__ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(TYPE_1__ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, unsigned long, unsigned int);
int main(void) {
  FILE *in, *out;
  struct pirate {
    char name[100];
    unsigned long booty;
    unsigned int beard_len;
  } p, blackbeard = {"Edward Tech", 950, 48};
  out = fopen("salo.txt", "w");
  if (!out) {
    perror("fopen");
    return 1;
  }
  if (!fwrite(&blackbeard, sizeof(struct pirate), 1, out)) {
    perror("fwrite");
    return 1;
  }
  if (fclose(out)) {
    perror("fclose");
    return 1;
  }
  in = fopen("salo.txt", "r");
  if (!in) {
    perror("fopen");
    return 1;
  }
  if (!fread(&p, sizeof(struct pirate), 1, in)) {
    perror("fread");
    return 1;
  }
  if (fclose(in)) {
    perror("fclose");
    return 1;
  }
  printf("name=\"%s\" booty=%lu beard_len=%u\n", p.name, p.booty, p.beard_len);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x108(%rbp),%rdi
lea    0xe70(%rip),%rsi
mov    $0x78,%edx
call   1060 <memcpy@plt>
lea    0xed7(%rip),%rdi
lea    0xed9(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d4 <main+0x64>
lea    0xec0(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f4 <main+0x184>
lea    -0x108(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x78,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
cmp    $0x0,%eax
jne    120f <main+0x9f>
lea    0xe8b(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f4 <main+0x184>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     123a <main+0xca>
lea    0xe67(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f4 <main+0x184>
lea    0xe37(%rip),%rdi
lea    0xe4f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1274 <main+0x104>
lea    0xe20(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f4 <main+0x184>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x78,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x0,%eax
jne    12af <main+0x13f>
lea    0xdfb(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f4 <main+0x184>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     12da <main+0x16a>
lea    0xdc7(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f4 <main+0x184>
lea    -0x90(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%ecx
lea    0xdb0(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0xf8,%rsp
mov    0xf00(%rip),%rax
mov    %rax,0x70(%rsp)
movups 0xee4(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movups 0xec8(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movups 0xeac(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movups 0xe90(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movups 0xe74(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movups 0xe58(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movups 0xe3c(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xea9(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1288 <main+0x128>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%ebp
mov    $0x78,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
test   %eax,%eax
je     12a4 <main+0x144>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
jne    1291 <main+0x131>
lea    0xe5b(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1288 <main+0x128>
mov    %rax,%rbx
lea    0x80(%rsp),%rdi
mov    $0x1,%ebp
mov    $0x78,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %eax,%eax
je     12ad <main+0x14d>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
jne    1291 <main+0x131>
mov    0xe8(%rsp),%rdx
mov    0xf0(%rsp),%ecx
lea    0xe28(%rip),%rdi
lea    0x80(%rsp),%rsi
call   1050 <printf@plt>
xor    %ebp,%ebp
jmp    12b9 <main+0x159>
lea    0xdf4(%rip),%rdi
jmp    1298 <main+0x138>
lea    0xdf8(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%ebp
jmp    12b9 <main+0x159>
lea    0xdde(%rip),%rdi
jmp    12b4 <main+0x154>
lea    0xde5(%rip),%rdi
call   1070 <perror@plt>
mov    %ebp,%eax
add    $0xf8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.pirate = type { [100 x i8], i64, i32 }
%struct.pirate.0 = type { i8*, i64, i32 }
@__const.main.blackbeard = %struct.pirate { [100 x i8] c"Edward Tech\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i64 950, i32 48 }
@.str = [9 x i8] c"salo.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [7 x i8] c"fwrite\00"
@.str.4 = [7 x i8] c"fclose\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [6 x i8] c"fread\00"
@.str.7 = [34 x i8] c"name=\22%s\22 booty=%lu beard_len=%u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca %struct.pirate
%5 = alloca %struct.pirate
store i32 0, i32* %1
%6 = bitcast %struct.pirate* %5 to i8*
%7 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %52
12: ; preds = %0
%13 = bitcast %struct.pirate* %5 to %struct.pirate.0*
%14 = load i32*, i32** %3
%15 = call i32 @fwrite(%struct.pirate.0* %13, i32 120, i32 1, i32* %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %52
19: ; preds = %12
%20 = load i32*, i32** %3
%21 = call i64 @fclose(i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %52
25: ; preds = %19
%26 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %26, i32** %2
%27 = load i32*, i32** %2
%28 = icmp ne i32* %27, null
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %52
31: ; preds = %25
%32 = bitcast %struct.pirate* %4 to %struct.pirate.0*
%33 = load i32*, i32** %2
%34 = call i32 @fread(%struct.pirate.0* %32, i32 120, i32 1, i32* %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %31
%37 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %1
br label %52
38: ; preds = %31
%39 = load i32*, i32** %2
%40 = call i64 @fclose(i32* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %52
44: ; preds = %38
%45 = getelementptr inbounds %struct.pirate, %struct.pirate* %4, i32 0, i32 0
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %45, i64 0, i64 0
%47 = getelementptr inbounds %struct.pirate, %struct.pirate* %4, i32 0, i32 1
%48 = load i64, i64* %47
%49 = getelementptr inbounds %struct.pirate, %struct.pirate* %4, i32 0, i32 2
%50 = load i32, i32* %49
%51 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %46, i64 %48, i32 %50)
br label %52
52: ; preds = %44, %42, %36, %29, %23, %17, %10
%53 = load i32, i32* %1
ret i32 %53
}

LLVM IR (-O2):
%struct.pirate = type { [100 x i8], i64, i32 }
%struct.pirate.0 = type { i8*, i64, i32 }
@__const.main.blackbeard = %struct.pirate { [100 x i8] c"Edward Tech\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00", i64 950, i32 48 }
@.str = [9 x i8] c"salo.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [7 x i8] c"fwrite\00"
@.str.4 = [7 x i8] c"fclose\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [6 x i8] c"fread\00"
@.str.7 = [34 x i8] c"name=\22%s\22 booty=%lu beard_len=%u\0A\00"
define i32 @main() {
%1 = alloca %struct.pirate
%2 = alloca %struct.pirate
%3 = getelementptr inbounds %struct.pirate, %struct.pirate* %1, i64 0, i32 0, i64 0
%4 = getelementptr inbounds %struct.pirate, %struct.pirate* %2, i64 0, i32 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %42
9: ; preds = %0
%10 = bitcast %struct.pirate* %2 to %struct.pirate.0*
%11 = call i32 @fwrite(%struct.pirate.0* %10, i32 120, i32 1, i32* %5)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %42
15: ; preds = %9
%16 = tail call i64 @fclose(i32* %5)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %42
20: ; preds = %15
%21 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %42
25: ; preds = %20
%26 = bitcast %struct.pirate* %1 to %struct.pirate.0*
%27 = call i32 @fread(%struct.pirate.0* %26, i32 120, i32 1, i32* %21)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %42
31: ; preds = %25
%32 = tail call i64 @fclose(i32* %21)
%33 = icmp eq i64 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %42
36: ; preds = %31
%37 = getelementptr inbounds %struct.pirate, %struct.pirate* %1, i64 0, i32 1
%38 = load i64, i64* %37
%39 = getelementptr inbounds %struct.pirate, %struct.pirate* %1, i64 0, i32 2
%40 = load i32, i32* %39
%41 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %3, i64 %38, i32 %40)
br label %42
42: ; preds = %36, %34, %29, %23, %18, %13, %7
%43 = phi i32 [ 1, %18 ], [ 1, %34 ], [ 0, %36 ], [ 1, %29 ], [ 1, %23 ], [ 1, %13 ], [ 1, %7 ]
ret i32 %43
}