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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ abort();
int close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int main(int argc, char **argv) {
  for (int i = 0; i < 10000; i++) {
    int fd = open(argv[0], O_RDONLY);
    if (fd == -1)
      abort();
    char buf[1024];
    ssize_t read_ret = read(fd, buf, sizeof(buf));
    if (read_ret == -1)
      abort();
    int ret = close(fd);
    if (ret == -1)
      abort();
  }
  puts("Test succeeded.");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2710,-0x14(%rbp)
jge    1209 <main+0xb9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11a6 <main+0x56>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x18(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0xffffffff,-0x424(%rbp)
jne    11d4 <main+0x84>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    %eax,-0x428(%rbp)
cmpl   $0xffffffff,-0x428(%rbp)
jne    11f6 <main+0xa6>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11fb <main+0xab>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1170 <main+0x20>
lea    0xdf0(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r15
mov    $0x2710,%ebx
mov    0x2e7a(%rip),%r12
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15),%rdi
mov    (%r12),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11d6 <main+0x86>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
je     11d6 <main+0x86>
mov    %ebp,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     11d6 <main+0x86>
add    $0xffffffff,%ebx
jne    1180 <main+0x30>
lea    0xe41(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [16 x i8] c"Test succeeded.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %11
11: ; preds = %40, %2
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 10000
br i1 %13, label %14, label %43
14: ; preds = %11
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDONLY
%19 = call i32 @open(i8* %17, i32 %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %14
%25 = load i32, i32* %7
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%27 = call i32 @read(i32 %25, i8* %26, i32 1024)
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 (...) @abort()
unreachable
32: ; preds = %24
%33 = load i32, i32* %7
%34 = call i32 @close(i32 %33)
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 (...) @abort()
unreachable
39: ; preds = %32
br label %40
40: ; preds = %39
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %11
43: ; preds = %11
%44 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [16 x i8] c"Test succeeded.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %7
5: ; preds = %25
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
ret i32 0
7: ; preds = %2, %25
%8 = phi i32 [ 0, %2 ], [ %26, %25 ]
%9 = load i8*, i8** %1
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 (...) @abort()
unreachable
15: ; preds = %7
%16 = call i32 @read(i32 %11, i8* %4, i32 1024)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 (...) @abort()
unreachable
20: ; preds = %15
%21 = tail call i32 @close(i32 %11)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i32 (...) @abort()
unreachable
25: ; preds = %20
%26 = add nuw nsw i32 %8, 1
%27 = icmp eq i32 %26, 10000
br i1 %27, label %5, label %7
}