#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*/ score;
typedef int /*<<< orphan*/ name;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, ...);
int main() {
  char name[20];
  short age;
  float score;
  char sex;
  int fd;
  int r;
  fd = open("test.dat", O_RDONLY);
  if (fd == -1) {
    printf("open file error:%m\n");
    exit(-1);
  }
  while (1) {
    r = read(fd, name, sizeof(name));
    if (r == 0) {
      break;
    }
    r = read(fd, &age, sizeof age);
    r = read(fd, &score, sizeof(score));
    r = read(fd, &sex, sizeof(char));
    printf("%s\t%4hd\t%.2f\t%c\n", name, age, score, sex);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    1199 <main+0x49>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    119e <main+0x4e>
mov    -0x30(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x14,%edx
mov    $0x0,%al
call   1050 <read@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    11c3 <main+0x73>
jmp    122d <main+0xdd>
mov    -0x30(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1050 <read@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <read@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1050 <read@plt>
mov    %eax,-0x34(%rbp)
lea    -0x20(%rbp),%rsi
movswl -0x22(%rbp),%edx
movss  -0x28(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsbl -0x29(%rbp),%ecx
lea    0xdfc(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    119e <main+0x4e>
mov    -0x30(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
lea    0xe92(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1241 <main+0xf1>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
mov    $0x14,%edx
mov    %eax,%edi
xor    %eax,%eax
call   1050 <read@plt>
test   %eax,%eax
je     1229 <main+0xd9>
lea    0xa(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0x9(%rsp),%r12
lea    0xe6e(%rip),%r13
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x2,%edx
mov    %ebx,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <read@plt>
mov    $0x4,%edx
mov    %ebx,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <read@plt>
mov    $0x1,%edx
mov    %ebx,%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <read@plt>
movswl 0xa(%rsp),%edx
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsbl 0x9(%rsp),%ecx
mov    %r13,%rdi
mov    %rbp,%rsi
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x14,%edx
mov    %ebx,%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <read@plt>
test   %eax,%eax
jne    11c0 <main+0x70>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc1(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"test.dat\00"
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"open file error:%m\0A\00"
@.str.2 = [17 x i8] c"%s\09%4hd\09%.2f\09%c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca i16
%4 = alloca float
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %0
br label %16
16: ; preds = %15, %23
%17 = load i32, i32* %6
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%19 = call i32 (i32, ...) @read(i32 %17, i8* %18, i64 20)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %16
br label %38
23: ; preds = %16
%24 = load i32, i32* %6
%25 = call i32 (i32, ...) @read(i32 %24, i16* %3, i64 2)
store i32 %25, i32* %7
%26 = load i32, i32* %6
%27 = call i32 (i32, ...) @read(i32 %26, float* %4, i64 4)
store i32 %27, i32* %7
%28 = load i32, i32* %6
%29 = call i32 (i32, ...) @read(i32 %28, i8* %5, i64 1)
store i32 %29, i32* %7
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%31 = load i16, i16* %3
%32 = sext i16 %31 to i32
%33 = load float, float* %4
%34 = fpext float %33 to double
%35 = load i8, i8* %5
%36 = sext i8 %35 to i32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %30, i32 %32, double %34, i32 %36)
br label %16
38: ; preds = %22
%39 = load i32, i32* %6
%40 = call i32 @close(i32 %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.dat\00"
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"open file error:%m\0A\00"
@.str.2 = [17 x i8] c"%s\09%4hd\09%.2f\09%c\0A\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca i16
%3 = alloca float
%4 = alloca i8
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%6 = bitcast i16* %2 to i8*
%7 = bitcast float* %3 to i8*
%8 = load i32, i32* @O_RDONLY
%9 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = call i32 (i32, ...) @read(i32 %9, i8* %5, i64 20)
%13 = icmp eq i32 %12, 0
br i1 %13, label %30, label %17
14: ; preds = %0
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 -1)
unreachable
17: ; preds = %11, %17
%18 = call i32 (i32, ...) @read(i32 %9, i16* %2, i64 2)
%19 = call i32 (i32, ...) @read(i32 %9, float* %3, i64 4)
%20 = call i32 (i32, ...) @read(i32 %9, i8* %4, i64 1)
%21 = load i16, i16* %2
%22 = sext i16 %21 to i32
%23 = load float, float* %3
%24 = fpext float %23 to double
%25 = load i8, i8* %4
%26 = sext i8 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %5, i32 %22, double %24, i32 %26)
%28 = call i32 (i32, ...) @read(i32 %9, i8* %5, i64 20)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %17
30: ; preds = %17, %11
%31 = call i32 @close(i32 %9)
ret i32 0
}