#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int main(int argc, char **argv) {
  int i, fd;
  char *file;
  sscanf(argv[1], " %d ", &i);
  file = argv[2];
  if (i < 1 || i > 1000000000 || !*file)
    return -1;
  while (i-- > 0) {
    fd = open(file, O_RDONLY);
    if (fd < 0)
      return -1;
    close(fd);
  }
  return 0;
}


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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xeab(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x14(%rbp)
jl     118e <main+0x5e>
cmpl   $0x3b9aca00,-0x14(%rbp)
jg     118e <main+0x5e>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    119a <main+0x6a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f2 <main+0xc2>
jmp    119f <main+0x6f>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
jle    11eb <main+0xbb>
mov    -0x20(%rbp),%rdi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11de <main+0xae>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f2 <main+0xc2>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
jmp    119f <main+0x6f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xeba(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1040 <sscanf@plt>
mov    0xc(%rsp),%eax
lea    -0x3b9aca01(%rax),%ecx
mov    $0xffffffff,%r14d
cmp    $0xc4653600,%ecx
jb     11a8 <main+0x78>
mov    0x10(%rbx),%rbx
cmpb   $0x0,(%rbx)
je     11a8 <main+0x78>
add    $0xffffffff,%eax
mov    %eax,0xc(%rsp)
mov    0x2e69(%rip),%rbp
nop
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
js     11a8 <main+0x78>
mov    %eax,%edi
call   1030 <close@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
test   %eax,%eax
jg     1180 <main+0x50>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c" %d \00"
@O_RDONLY = 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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %6)
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
store i8* %15, i8** %8
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 1
br i1 %17, label %25, label %18
18: ; preds = %2
%19 = load i32, i32* %6
%20 = icmp sgt i32 %19, 1000000000
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i8*, i8** %8
%23 = load i8, i8* %22
%24 = icmp ne i8 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %21, %18, %2
store i32 -1, i32* %3
br label %42
26: ; preds = %21
br label %27
27: ; preds = %38, %26
%28 = load i32, i32* %6
%29 = add nsw i32 %28, -1
store i32 %29, i32* %6
%30 = icmp sgt i32 %28, 0
br i1 %30, label %31, label %41
31: ; preds = %27
%32 = load i8*, i8** %8
%33 = load i32, i32* @O_RDONLY
%34 = call i32 @open(i8* %32, i32 %33)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %31
store i32 -1, i32* %3
br label %42
38: ; preds = %31
%39 = load i32, i32* %7
%40 = call i32 @close(i32 %39)
br label %27
41: ; preds = %27
store i32 0, i32* %3
br label %42
42: ; preds = %41, %37, %25
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [5 x i8] c" %d \00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = load i32, i32* %3
%11 = add i32 %10, -1000000001
%12 = icmp ult i32 %11, -1000000000
br i1 %12, label %27, label %13
13: ; preds = %2
%14 = load i8, i8* %9
%15 = icmp eq i8 %14, 0
br i1 %15, label %27, label %16
16: ; preds = %13
%17 = add nsw i32 %10, -1
store i32 %17, i32* %3
br label %18
18: ; preds = %16, %22
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %9, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %18
%23 = call i32 @close(i32 %20)
%24 = load i32, i32* %3
%25 = add nsw i32 %24, -1
store i32 %25, i32* %3
%26 = icmp sgt i32 %24, 0
br i1 %26, label %18, label %27
27: ; preds = %18, %22, %2, %13
%28 = phi i32 [ -1, %13 ], [ -1, %2 ], [ -1, %18 ], [ 0, %22 ]
ret i32 %28
}