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

/* Variables and functions */
int atoi(char *);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int i, j = atoi(argv[2]);
  size_t x;
  FILE *files[j];
  char buf[100];
  if (argc < 3) {
    return -1;
  }
  for (i = 0; i < j; i++) {
    files[i] = fopen(argv[1], "r+w");
    if (files[i] != NULL) {
      printf("Opening success\n");
      x = fread(buf, sizeof(buf), 1, files[i]);
      printf("read %d blocks: %s\n", x, buf);
      printf("wrote %d bytes\n", fwrite("hello driver", sizeof("hello driver"),
                                        sizeof("hello driver"), files[i]));
      fclose(files[i]);
    } else {
      printf("Opening failed: %d\n", errno);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xb0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11d3 <main+0x73>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0xa4(%rbp)
jmp    12ea <main+0x18a>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12e0 <main+0x180>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe0b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rdx
mov    -0xb0(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     12b6 <main+0x156>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xb0(%rbp),%rax
lea    -0xa0(%rbp),%rdi
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    $0x64,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    -0xa0(%rbp),%rdx
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xb0(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xdb8(%rip),%rdi
mov    $0xd,%edx
mov    %edx,%esi
call   1080 <fwrite@plt>
mov    %eax,%esi
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xb0(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <fclose@plt>
jmp    12cd <main+0x16d>
mov    0x2d23(%rip),%rax
mov    (%rax),%esi
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12d2 <main+0x172>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11da <main+0x7a>
movl   $0x0,-0xa4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x10(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
mov    $0xffffffff,%eax
cmp    $0x3,%r14d
jl     1259 <main+0xe9>
test   %ebp,%ebp
jle    1257 <main+0xe7>
lea    0xe53(%rip),%r14
mov    %rsp,%r13
lea    0xe61(%rip),%r15
jmp    11dc <main+0x6c>
nopl   0x0(%rax)
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
lea    0xe65(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0xffffffff,%ebp
je     1257 <main+0xe7>
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c0 <main+0x50>
mov    %rax,%r12
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
mov    $0x64,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
lea    0xdec(%rip),%rdi
mov    %rax,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdfc(%rip),%rdi
mov    $0xd,%esi
mov    $0xd,%edx
mov    %r12,%rcx
call   1090 <fwrite@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
add    $0xffffffff,%ebp
jne    11dc <main+0x6c>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"r+w\00"
@.str.1 = [17 x i8] c"Opening success\0A\00"
@.str.2 = [20 x i8] c"read %d blocks: %s\0A\00"
@.str.3 = [16 x i8] c"wrote %d bytes\0A\00"
@.str.4 = [13 x i8] c"hello driver\00"
@.str.5 = [20 x i8] c"Opening failed: %d\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca [100 x i8]
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %9
%20 = alloca i32*, i64 %18
store i64 %18, i64* %10
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 3
br i1 %22, label %23, label %24
23: ; preds = %2
store i32 -1, i32* %3
store i32 1, i32* %12
br label %72
24: ; preds = %2
store i32 0, i32* %6
br label %25
25: ; preds = %68, %24
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %71
29: ; preds = %25
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32*, i32** %20, i64 %35
store i32* %33, i32** %36
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32*, i32** %20, i64 %38
%40 = load i32*, i32** %39
%41 = icmp ne i32* %40, null
br i1 %41, label %42, label %64
42: ; preds = %29
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32*, i32** %20, i64 %46
%48 = load i32*, i32** %47
%49 = call i64 @fread(i8* %44, i32 100, i32 1, i32* %48)
store i64 %49, i64* %8
%50 = load i64, i64* %8
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 %50, i8* %51)
%53 = load i32, i32* %6
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32*, i32** %20, i64 %54
%56 = load i32*, i32** %55
%57 = call i32 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 13, i32 13, i32* %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %6
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32*, i32** %20, i64 %60
%62 = load i32*, i32** %61
%63 = call i32 @fclose(i32* %62)
br label %67
64: ; preds = %29
%65 = load i32, i32* @errno
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %64, %42
br label %68
68: ; preds = %67
%69 = load i32, i32* %6
%70 = add nsw i32 %69, 1
store i32 %70, i32* %6
br label %25
71: ; preds = %25
store i32 0, i32* %12
br label %72
72: ; preds = %71, %23
%73 = load i8*, i8** %9
%74 = load i32, i32* %12
switch i32 %74, label %77 [
i32 0, label %75
i32 1, label %75
]
75: ; preds = %72, %72
%76 = load i32, i32* %3
ret i32 %76
77: ; preds = %72
unreachable
}

LLVM IR (-O2):
@.str = [4 x i8] c"r+w\00"
@.str.2 = [20 x i8] c"read %d blocks: %s\0A\00"
@.str.3 = [16 x i8] c"wrote %d bytes\0A\00"
@.str.4 = [13 x i8] c"hello driver\00"
@.str.5 = [20 x i8] c"Opening failed: %d\0A\00"
@errno = global i32 0
@str = [16 x i8] c"Opening success\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds i8*, i8** %1, i64 2
%5 = load i8*, i8** %4
%6 = tail call i32 @atoi(i8* %5)
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%8 = icmp slt i32 %0, 3
br i1 %8, label %31, label %9
9: ; preds = %2
%10 = icmp sgt i32 %6, 0
br i1 %10, label %11, label %31
11: ; preds = %9
%12 = getelementptr inbounds i8*, i8** %1, i64 1
br label %13
13: ; preds = %11, %28
%14 = phi i32 [ 0, %11 ], [ %29, %28 ]
%15 = load i8*, i8** %12
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %25, label %18
18: ; preds = %13
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%20 = call i64 @fread(i8* %7, i32 100, i32 1, i32* %16)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 %20, i8* %7)
%22 = call i32 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 13, i32 13, i32* %16)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = call i32 @fclose(i32* %16)
br label %28
25: ; preds = %13
%26 = load i32, i32* @errno
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %18, %25
%29 = add nuw nsw i32 %14, 1
%30 = icmp eq i32 %29, %6
br i1 %30, label %31, label %13
31: ; preds = %28, %9, %2
%32 = phi i32 [ -1, %2 ], [ 0, %9 ], [ 0, %28 ]
ret i32 %32
}