#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int main() {
  int i;
  FILE *fp;
  for (i = 0; i < 10; i++) {
    fp = fdopen(i, "r");
    printf("%d: ", i);
    if (fp) {
      char str[100];
      fgets(str, 100, fp);
      puts(str);
      fclose(fp);
    } else {
      puts("FAIL");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    11e8 <main+0x98>
mov    -0x8(%rbp),%edi
lea    0xe83(%rip),%rsi
call   1070 <fdopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe72(%rip),%rdi
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11c9 <main+0x79>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
lea    -0x80(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
jmp    11d5 <main+0x85>
lea    0xe37(%rip),%rdi
call   1030 <puts@plt>
jmp    11da <main+0x8a>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1169 <main+0x19>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
xor    %ebx,%ebx
lea    0xe99(%rip),%r14
lea    0xe94(%rip),%r15
lea    0xe92(%rip),%r12
mov    %rsp,%r13
jmp    1190 <main+0x40>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <puts@plt>
add    $0x1,%ebx
cmp    $0xa,%ebx
je     11ce <main+0x7e>
mov    %ebx,%edi
mov    %r14,%rsi
call   1070 <fdopen@plt>
mov    %rax,%rbp
mov    %r15,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
test   %rbp,%rbp
je     1180 <main+0x30>
mov    %r13,%rdi
mov    $0x64,%esi
mov    %rbp,%rdx
call   1060 <fgets@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
jmp    1188 <main+0x38>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"%d: \00"
@.str.2 = [5 x i8] c"FAIL\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [100 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
br label %5
5: ; preds = %26, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %29
8: ; preds = %5
%9 = load i32, i32* %2
%10 = call i32* @fdopen(i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %3
%11 = load i32, i32* %2
%12 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32*, i32** %3
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %23
15: ; preds = %8
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%17 = load i32*, i32** %3
%18 = call i32 @fgets(i8* %16, i32 100, i32* %17)
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%20 = call i32 @puts(i8* %19)
%21 = load i32*, i32** %3
%22 = call i32 @fclose(i32* %21)
br label %25
23: ; preds = %8
%24 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %15
br label %26
26: ; preds = %25
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
store i32 %28, i32* %2
br label %5
29: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"%d: \00"
@.str.2 = [5 x i8] c"FAIL\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %14
%4 = phi i32 [ 0, %0 ], [ %15, %14 ]
%5 = call i32* @fdopen(i32 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%7 = icmp eq i32* %5, null
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = call i32 @fgets(i8* %2, i32 100, i32* %5)
%10 = call i32 @puts(i8* %2)
%11 = call i32 @fclose(i32* %5)
br label %14
12: ; preds = %3
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %8, %12
%15 = add nuw nsw i32 %4, 1
%16 = icmp eq i32 %15, 10
br i1 %16, label %17, label %3
17: ; preds = %14
ret i32 0
}