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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(void *, int, int, int /*<<< orphan*/ *);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  char name[32];
  int age;
  char address[128];
  FILE *fp;
  long position;
  fp = fopen("prof.bin", "rb");
  if (fp == NULL) {
    printf("Can't open file!\n");
    return -1;
  }
  position = ftell(fp);
  printf("position: %ld\n", position);
  fread((void *)name, sizeof(char), 32, fp);
  printf("name: %s\n", name);
  position = ftell(fp);
  printf("position: %ld\n", position);
  fread((void *)&age, sizeof(age), 1, fp);
  printf("age: %d\n", age);
  position = ftell(fp);
  printf("position: %ld\n", position);
  fread((void *)address, sizeof(char), 128, fp);
  printf("address: %s\n", address);
  position = ftell(fp);
  printf("position: %ld\n", position);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0xc8(%rbp)
cmpq   $0x0,-0xc8(%rbp)
jne    11a4 <main+0x54>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e0 <main+0x190>
mov    -0xc8(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0xd0(%rbp)
mov    -0xd0(%rbp),%rsi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    -0xc8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x20,%edx
call   1030 <fread@plt>
lea    -0x30(%rbp),%rsi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc8(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0xd0(%rbp)
mov    -0xd0(%rbp),%rsi
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x34(%rbp),%rdi
mov    -0xc8(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x34(%rbp),%esi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc8(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0xd0(%rbp)
mov    -0xd0(%rbp),%rsi
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc0(%rbp),%rdi
mov    -0xc8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x80,%edx
call   1030 <fread@plt>
lea    -0xc0(%rbp),%rsi
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc8(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0xd0(%rbp)
mov    -0xd0(%rbp),%rsi
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc8(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xb8,%rsp
lea    0xe8c(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1273 <main+0x113>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <ftell@plt>
lea    0xe71(%rip),%r14
xor    %r15d,%r15d
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x20,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
lea    0xe4f(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    0xc(%rsp),%esi
lea    0xe18(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x80,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
lea    0xde4(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1285 <main+0x125>
lea    0xdc1(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"prof.bin\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [18 x i8] c"Can't open file!\0A\00"
@.str.3 = [15 x i8] c"position: %ld\0A\00"
@.str.4 = [10 x i8] c"name: %s\0A\00"
@.str.5 = [9 x i8] c"age: %d\0A\00"
@.str.6 = [13 x i8] c"address: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = alloca i32*
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %46
12: ; preds = %0
%13 = load i32*, i32** %5
%14 = call i64 @ftell(i32* %13)
store i64 %14, i64* %6
%15 = load i64, i64* %6
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 %15)
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%18 = load i32*, i32** %5
%19 = call i32 @fread(i8* %17, i32 1, i32 32, i32* %18)
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %20)
%22 = load i32*, i32** %5
%23 = call i64 @ftell(i32* %22)
store i64 %23, i64* %6
%24 = load i64, i64* %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 %24)
%26 = bitcast i32* %3 to i8*
%27 = load i32*, i32** %5
%28 = call i32 @fread(i8* %26, i32 4, i32 1, i32* %27)
%29 = load i32, i32* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = load i32*, i32** %5
%32 = call i64 @ftell(i32* %31)
store i64 %32, i64* %6
%33 = load i64, i64* %6
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 %33)
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%36 = load i32*, i32** %5
%37 = call i32 @fread(i8* %35, i32 1, i32 128, i32* %36)
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %38)
%40 = load i32*, i32** %5
%41 = call i64 @ftell(i32* %40)
store i64 %41, i64* %6
%42 = load i64, i64* %6
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 %42)
%44 = load i32*, i32** %5
%45 = call i32 @fclose(i32* %44)
store i32 0, i32* %1
br label %46
46: ; preds = %12, %10
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@.str = [9 x i8] c"prof.bin\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.3 = [15 x i8] c"position: %ld\0A\00"
@.str.4 = [10 x i8] c"name: %s\0A\00"
@.str.5 = [9 x i8] c"age: %d\0A\00"
@.str.6 = [13 x i8] c"address: %s\0A\00"
@str = [17 x i8] c"Can't open file!\00"
define i32 @main() {
%1 = alloca [32 x i8]
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %28
11: ; preds = %0
%12 = tail call i64 @ftell(i32* %7)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 %12)
%14 = call i32 @fread(i8* %4, i32 1, i32 32, i32* %7)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%16 = call i64 @ftell(i32* %7)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 %16)
%18 = call i32 @fread(i8* %5, i32 4, i32 1, i32* %7)
%19 = load i32, i32* %2
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%21 = call i64 @ftell(i32* %7)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 %21)
%23 = call i32 @fread(i8* %6, i32 1, i32 128, i32* %7)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %6)
%25 = call i64 @ftell(i32* %7)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 %25)
%27 = call i32 @fclose(i32* %7)
br label %28
28: ; preds = %11, %9
%29 = phi i32 [ -1, %9 ], [ 0, %11 ]
ret i32 %29
}