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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDWR;
int atoi(char *);
int close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int i, n;
  if (argc != 3) {
    fprintf(stderr, "usage: %s PATH REPEAT\n", argv[0]);
    return EXIT_FAILURE;
  }
  n = atoi(argv[2]);
  for (i = 0; i < n; i++) {
    int fd;
    fd = open(argv[1], O_RDWR);
    if (fd == -1) {
      perror("open");
      return EXIT_FAILURE;
    }
    if (close(fd) == -1) {
      perror("open");
      return EXIT_FAILURE;
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119d <main+0x4d>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    124d <main+0xfd>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1241 <main+0xf1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1200 <main+0xb0>
lea    0xe2d(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    124d <main+0xfd>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    122e <main+0xde>
lea    0xdff(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    124d <main+0xfd>
jmp    1233 <main+0xe3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b4 <main+0x64>
mov    0x2d80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11a4 <main+0x54>
mov    0x10(%rbx),%rdi
call   1070 <atoi@plt>
mov    0x2e59(%rip),%r14
test   %eax,%eax
jle    11c3 <main+0x73>
mov    %eax,%ebp
mov    0x2e6c(%rip),%r15
nopl   0x0(%rax)
mov    0x8(%rbx),%rdi
mov    (%r15),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11d1 <main+0x81>
mov    %eax,%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
je     11d1 <main+0x81>
add    $0xffffffff,%ebp
jne    1180 <main+0x30>
jmp    11c3 <main+0x73>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe49(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e0d(%rip),%r14
mov    (%r14),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe3f(%rip),%rdi
call   1060 <perror@plt>
jmp    11bc <main+0x6c>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"usage: %s PATH REPEAT\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@EXIT_SUCCESS = 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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
store i32 %17, i32* %3
br label %51
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %7
store i32 0, i32* %6
br label %23
23: ; preds = %46, %18
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %49
27: ; preds = %23
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = load i32, i32* @O_RDWR
%32 = call i32 @open(i8* %30, i32 %31)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %27
%36 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
store i32 %37, i32* %3
br label %51
38: ; preds = %27
%39 = load i32, i32* %8
%40 = call i32 @close(i32 %39)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
store i32 %44, i32* %3
br label %51
45: ; preds = %38
br label %46
46: ; preds = %45
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %23
49: ; preds = %23
%50 = load i32, i32* @EXIT_SUCCESS
store i32 %50, i32* %3
br label %51
51: ; preds = %49, %42, %35, %11
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"usage: %s PATH REPEAT\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %31
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %31
13: ; preds = %8
%14 = getelementptr inbounds i8*, i8** %1, i64 1
br label %17
15: ; preds = %25
%16 = icmp eq i32 %28, %11
br i1 %16, label %31, label %17
17: ; preds = %13, %15
%18 = phi i32 [ 0, %13 ], [ %28, %15 ]
%19 = load i8*, i8** %14
%20 = load i32, i32* @O_RDWR
%21 = tail call i32 @open(i8* %19, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %31
25: ; preds = %17
%26 = tail call i32 @close(i32 %21)
%27 = icmp eq i32 %26, -1
%28 = add nuw nsw i32 %18, 1
br i1 %27, label %29, label %15
29: ; preds = %25
%30 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %15, %8, %23, %29, %4
%32 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_FAILURE, %23 ], [ @EXIT_FAILURE, %29 ], [ @EXIT_SUCCESS, %8 ], [ @EXIT_SUCCESS, %15 ]
%33 = load i32, i32* %32
ret i32 %33
}