#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(int *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
char *strdup(char const *);
int /*<<< orphan*/ usage();
int main(int argc, const char *argv[]) {
  FILE *stream;
  size_t numread;
  int buf[6];
  size_t i, nelmts = 6;
  char *fname = NULL;
  if (argc != 2) {
    usage();
    exit(1);
  }
  fname = strdup(argv[1]);
  if ((stream = fopen(fname, "rb")) != NULL) {
    numread = fread(buf, sizeof(int), nelmts, stream);
    printf("Number of items read = %llu\n", (unsigned long long)numread);
    for (i = 0; i < nelmts; i++) {
      printf("%d ", buf[i]);
    }
    printf("\n");
    fclose(stream);
  } else
    printf("File %s could not be opened\n", fname);
  free(fname);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x6,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c1 <main+0x41>
mov    $0x0,%al
call   1070 <usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1275 <main+0xf5>
lea    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
call   1040 <fread@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x50(%rbp),%rax
jae    1259 <main+0xd9>
mov    -0x48(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    1224 <main+0xa4>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1287 <main+0x107>
mov    -0x58(%rbp),%rsi
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
cmp    $0x2,%edi
jne    1282 <main+0xf2>
mov    0x8(%rsi),%rdi
call   10b0 <strdup@plt>
mov    %rax,%r14
lea    0xe4b(%rip),%rsi
mov    %rax,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     125d <main+0xcd>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x6,%edx
mov    $0x4,%esi
mov    %rax,%rcx
call   1050 <fread@plt>
lea    0xe1e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%rsp),%esi
lea    0xe27(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
jmp    126e <main+0xde>
lea    0xdc0(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1080 <usage@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [29 x i8] c"Number of items read = %llu\0A\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [29 x i8] c"File %s could not be opened\0A\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 [6 x i32]
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 6, i64* %10
store i8* null, i8** %11
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 (...) @usage()
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i8* @strdup(i8* %20)
store i8* %21, i8** %11
%22 = load i8*, i8** %11
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %23, i32** %6
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %48
25: ; preds = %17
%26 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 0
%27 = load i64, i64* %10
%28 = load i32*, i32** %6
%29 = call i64 @fread(i32* %26, i32 4, i64 %27, i32* %28)
store i64 %29, i64* %7
%30 = load i64, i64* %7
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i64 %30)
store i64 0, i64* %9
br label %32
32: ; preds = %41, %25
%33 = load i64, i64* %9
%34 = load i64, i64* %10
%35 = icmp ult i64 %33, %34
br i1 %35, label %36, label %44
36: ; preds = %32
%37 = load i64, i64* %9
%38 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %36
%42 = load i64, i64* %9
%43 = add i64 %42, 1
store i64 %43, i64* %9
br label %32
44: ; preds = %32
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
br label %51
48: ; preds = %17
%49 = load i8*, i8** %11
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %48, %44
%52 = load i8*, i8** %11
%53 = call i32 @free(i8* %52)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [29 x i8] c"Number of items read = %llu\0A\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.4 = [29 x i8] c"File %s could not be opened\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [6 x i32]
%4 = bitcast [6 x i32]* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 (...) @usage()
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i8* @strdup(i8* %11)
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %38, label %15
15: ; preds = %9
%16 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%17 = call i64 @fread(i32* %16, i32 4, i64 6, i32* %13)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i64 %17)
%19 = load i32, i32* %16
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 1
%22 = load i32, i32* %21
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 2
%25 = load i32, i32* %24
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 3
%28 = load i32, i32* %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 4
%31 = load i32, i32* %30
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 5
%34 = load i32, i32* %33
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = tail call i32 @putchar(i32 10)
%37 = tail call i32 @fclose(i32* %13)
br label %40
38: ; preds = %9
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %12)
br label %40
40: ; preds = %38, %15
%41 = tail call i32 @free(i8* %12)
ret i32 0
}