#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 __s32;

/* Variables and functions */
int /*<<< orphan*/ F_GETFD;
int fcntl(int, int /*<<< orphan*/);
int getdtablesize();
int /*<<< orphan*/ showFDDetail(int);
void showFDInfo() {
  int numHandles = getdtablesize();
  __s32 i;
  for (i = 0; i < numHandles; i++) {
    __s32 fd_flags = fcntl(i, F_GETFD);
    if (fd_flags == -1)
      continue;
    showFDDetail(i);
  }
}


x86 assembly (clang, -O0):
<showFDInfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <getdtablesize@plt>
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    118e <showFDInfo+0x5e>
mov    -0x8(%rbp),%edi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1178 <showFDInfo+0x48>
jmp    1180 <showFDInfo+0x50>
mov    -0x8(%rbp),%edi
call   1040 <showFDDetail@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1149 <showFDInfo+0x19>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<showFDInfo>:
push   %rbp
push   %r14
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getdtablesize@plt>
test   %eax,%eax
jle    116f <showFDInfo+0x3f>
mov    %eax,%ebp
mov    0x2e96(%rip),%r14
jmp    1157 <showFDInfo+0x27>
nopl   0x0(%rax)
add    $0x1,%ebx
cmp    %ebx,%ebp
je     116f <showFDInfo+0x3f>
mov    (%r14),%esi
mov    %ebx,%edi
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1150 <showFDInfo+0x20>
mov    %ebx,%edi
call   1040 <showFDDetail@plt>
jmp    1150 <showFDInfo+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFD = global i32 0
define void @showFDInfo() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (...) @getdtablesize()
store i32 %4, i32* %1
store i32 0, i32* %2
br label %5
5: ; preds = %19, %0
%6 = load i32, i32* %2
%7 = load i32, i32* %1
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %22
9: ; preds = %5
%10 = load i32, i32* %2
%11 = load i32, i32* @F_GETFD
%12 = call i32 @fcntl(i32 %10, i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %9
br label %19
16: ; preds = %9
%17 = load i32, i32* %2
%18 = call i32 @showFDDetail(i32 %17)
br label %19
19: ; preds = %16, %15
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
br label %5
22: ; preds = %5
ret void
}

LLVM IR (-O2):
@F_GETFD = global i32 0
define void @showFDInfo() {
%1 = tail call i32 (...) @getdtablesize()
%2 = icmp sgt i32 %1, 0
br i1 %2, label %3, label %13
3: ; preds = %0, %10
%4 = phi i32 [ %11, %10 ], [ 0, %0 ]
%5 = load i32, i32* @F_GETFD
%6 = tail call i32 @fcntl(i32 %4, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i32 @showFDDetail(i32 %4)
br label %10
10: ; preds = %3, %8
%11 = add nuw nsw i32 %4, 1
%12 = icmp eq i32 %11, %1
br i1 %12, label %13, label %3
13: ; preds = %10, %0
ret void
}