#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*/ digimons;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fwrite(struct digimon *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int scanf(char *, char *, unsigned int *);
int /*<<< orphan*/ stderr;
int main(void) {
  struct digimon {
    char name[10];
    unsigned level;
  };
  struct digimon digimons[4];
  for (unsigned i = 0; i < 4; i++) {
    if (scanf("%9s %u", digimons[i].name, &digimons[i].level) != 2) {
      fprintf(stderr, "error\n");
      return 1;
    }
  }
  printf("sizeof(char [10]) = %zu\n", sizeof(char[10]));
  printf("sizeof(unsigned) = %zu\n", sizeof(unsigned));
  printf("sizeof(struct digimon) = %zu\n", sizeof(struct digimon));
  printf("sizeof(digimons) = %zu\n", sizeof(digimons));
  FILE *file = fopen("digimon.save", "w");
  fwrite(digimons, sizeof(struct digimon), 4, file);
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x4,-0x54(%rbp)
jae    11e9 <main+0x89>
mov    -0x54(%rbp),%eax
lea    -0x50(%rbp),%rsi
shl    $0x4,%rax
add    %rax,%rsi
mov    -0x54(%rbp),%eax
lea    -0x50(%rbp),%rdx
shl    $0x4,%rax
add    %rax,%rdx
add    $0xc,%rdx
lea    0xe59(%rip),%rdi
call   1060 <scanf@plt>
cmp    $0x2,%eax
je     11d6 <main+0x76>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126b <main+0x10b>
jmp    11db <main+0x7b>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1176 <main+0x16>
lea    0xe1e(%rip),%rdi
mov    $0xa,%esi
call   1040 <printf@plt>
lea    0xe26(%rip),%rdi
mov    $0x4,%esi
call   1040 <printf@plt>
lea    0xe2d(%rip),%rdi
mov    $0x10,%esi
call   1040 <printf@plt>
lea    0xe3a(%rip),%rdi
mov    $0x40,%esi
call   1040 <printf@plt>
lea    0xe41(%rip),%rdi
lea    0xe47(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x60(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x60(%rbp),%rcx
mov    $0x10,%esi
mov    $0x4,%edx
call   1080 <fwrite@plt>
mov    -0x60(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
lea    0xc(%rsp),%rdx
lea    0xe8f(%rip),%rdi
mov    %rsp,%rsi
call   1060 <scanf@plt>
cmp    $0x2,%eax
jne    1256 <main+0xf6>
lea    0x10(%rsp),%rsi
lea    0x1c(%rsp),%rdx
lea    0xe6d(%rip),%rdi
call   1060 <scanf@plt>
cmp    $0x2,%eax
jne    1256 <main+0xf6>
lea    0x20(%rsp),%rsi
lea    0x2c(%rsp),%rdx
lea    0xe4e(%rip),%rdi
call   1060 <scanf@plt>
cmp    $0x2,%eax
jne    1256 <main+0xf6>
lea    0x30(%rsp),%rsi
lea    0x3c(%rsp),%rdx
lea    0xe2f(%rip),%rdi
call   1060 <scanf@plt>
cmp    $0x2,%eax
jne    1256 <main+0xf6>
lea    0xe2c(%rip),%rdi
mov    $0xa,%esi
call   1040 <printf@plt>
lea    0xe34(%rip),%rdi
mov    $0x4,%esi
call   1040 <printf@plt>
lea    0xe3b(%rip),%rdi
mov    $0x10,%esi
call   1040 <printf@plt>
lea    0xe48(%rip),%rdi
mov    $0x40,%esi
call   1040 <printf@plt>
lea    0xe4f(%rip),%rdi
lea    0xe55(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x10,%esi
mov    $0x4,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1270 <main+0x110>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xda1(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.digimon = type { [10 x i8], i32 }
%struct.digimon.0 = type opaque
@.str = [7 x i8] c"%9s %u\00"
@stderr = global i32 0
@.str.1 = [7 x i8] c"error\0A\00"
@.str.2 = [25 x i8] c"sizeof(char [10]) = %zu\0A\00"
@.str.3 = [24 x i8] c"sizeof(unsigned) = %zu\0A\00"
@.str.4 = [30 x i8] c"sizeof(struct digimon) = %zu\0A\00"
@.str.5 = [24 x i8] c"sizeof(digimons) = %zu\0A\00"
@.str.6 = [13 x i8] c"digimon.save\00"
@.str.7 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x %struct.digimon]
%3 = alloca i32
%4 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %3
br label %5
5: ; preds = %24, %0
%6 = load i32, i32* %3
%7 = icmp ult i32 %6, 4
br i1 %7, label %8, label %27
8: ; preds = %5
%9 = load i32, i32* %3
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [4 x %struct.digimon], [4 x %struct.digimon]* %2, i64 0, i64 %10
%12 = getelementptr inbounds %struct.digimon, %struct.digimon* %11, i32 0, i32 0
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%14 = load i32, i32* %3
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [4 x %struct.digimon], [4 x %struct.digimon]* %2, i64 0, i64 %15
%17 = getelementptr inbounds %struct.digimon, %struct.digimon* %16, i32 0, i32 1
%18 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %13, i32* %17)
%19 = icmp ne i32 %18, 2
br i1 %19, label %20, label %23
20: ; preds = %8
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %39
23: ; preds = %8
br label %24
24: ; preds = %23
%25 = load i32, i32* %3
%26 = add i32 %25, 1
store i32 %26, i32* %3
br label %5
27: ; preds = %5
%28 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 10)
%29 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 4)
%30 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 16)
%31 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 64)
%32 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %32, i32** %4
%33 = getelementptr inbounds [4 x %struct.digimon], [4 x %struct.digimon]* %2, i64 0, i64 0
%34 = bitcast %struct.digimon* %33 to %struct.digimon.0*
%35 = load i32*, i32** %4
%36 = call i32 @fwrite(%struct.digimon.0* %34, i32 16, i32 4, i32* %35)
%37 = load i32*, i32** %4
%38 = call i32 @fclose(i32* %37)
store i32 0, i32* %1
br label %39
39: ; preds = %27, %20
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
%struct.digimon = type { [10 x i8], i32 }
%struct.digimon.0 = type opaque
@.str = [7 x i8] c"%9s %u\00"
@stderr = global i32 0
@.str.1 = [7 x i8] c"error\0A\00"
@.str.2 = [25 x i8] c"sizeof(char [10]) = %zu\0A\00"
@.str.3 = [24 x i8] c"sizeof(unsigned) = %zu\0A\00"
@.str.4 = [30 x i8] c"sizeof(struct digimon) = %zu\0A\00"
@.str.5 = [24 x i8] c"sizeof(digimons) = %zu\0A\00"
@.str.6 = [13 x i8] c"digimon.save\00"
@.str.7 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca [4 x %struct.digimon]
%2 = getelementptr inbounds [4 x %struct.digimon], [4 x %struct.digimon]* %1, i64 0, i64 0, i32 0, i64 0
%3 = getelementptr inbounds [4 x %struct.digimon], [4 x %struct.digimon]* %1, i64 0, i64 0, i32 1
%4 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %2, i32* %3)
%5 = icmp eq i32 %4, 2
br i1 %5, label %6, label %30
6: ; preds = %0
%7 = getelementptr inbounds [4 x %struct.digimon], [4 x %struct.digimon]* %1, i64 0, i64 1, i32 0, i64 0
%8 = getelementptr inbounds [4 x %struct.digimon], [4 x %struct.digimon]* %1, i64 0, i64 1, i32 1
%9 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %7, i32* %8)
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %30
11: ; preds = %6
%12 = getelementptr inbounds [4 x %struct.digimon], [4 x %struct.digimon]* %1, i64 0, i64 2, i32 0, i64 0
%13 = getelementptr inbounds [4 x %struct.digimon], [4 x %struct.digimon]* %1, i64 0, i64 2, i32 1
%14 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %12, i32* %13)
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %30
16: ; preds = %11
%17 = getelementptr inbounds [4 x %struct.digimon], [4 x %struct.digimon]* %1, i64 0, i64 3, i32 0, i64 0
%18 = getelementptr inbounds [4 x %struct.digimon], [4 x %struct.digimon]* %1, i64 0, i64 3, i32 1
%19 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %17, i32* %18)
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %30
21: ; preds = %16
%22 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 10)
%23 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 4)
%24 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 16)
%25 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 64)
%26 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%27 = bitcast [4 x %struct.digimon]* %1 to %struct.digimon.0*
%28 = call i32 @fwrite(%struct.digimon.0* %27, i32 16, i32 4, i32* %26)
%29 = call i32 @fclose(i32* %26)
br label %33
30: ; preds = %16, %11, %6, %0
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %30, %21
%34 = phi i32 [ 0, %21 ], [ 1, %30 ]
ret i32 %34
}