#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 */
scalar_t__ EINTR;
int /*<<< orphan*/ _pfatal(int /*<<< orphan*/ *, int /*<<< orphan*/, char *);
int close(int);
scalar_t__ errno;
void fd_close(int fd) {
  int ret;
  do {
    ret = close(fd);
  } while (ret == -1 && errno == EINTR);
  if (ret < 0)
    _pfatal(NULL, 0, "fd_close");
  ;
}


x86 assembly (clang, -O0):
<fd_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x8(%rbp)
mov    %al,-0x9(%rbp)
jne    115f <fd_close+0x3f>
mov    0x2e94(%rip),%rax
mov    (%rax),%rax
mov    0x2e82(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    112b <fd_close+0xb>
cmpl   $0x0,-0x8(%rbp)
jge    1186 <fd_close+0x66>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
lea    0xe7f(%rip),%rdx
call   1040 <_pfatal@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fd_close>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%ebx
mov    0x2eb2(%rip),%r14
mov    0x2ea3(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    1154 <fd_close+0x34>
mov    (%r15),%rcx
cmp    %rcx,(%r14)
je     1140 <fd_close+0x20>
test   %eax,%eax
js     115e <fd_close+0x3e>
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe9b(%rip),%rdx
xor    %edi,%edi
xor    %esi,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <_pfatal@plt>

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@.str = [9 x i8] c"fd_close\00"
define void @fd_close(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
br label %4
4: ; preds = %14, %1
%5 = load i32, i32* %2
%6 = call i32 @close(i32 %5)
store i32 %6, i32* %3
br label %7
7: ; preds = %4
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i64, i64* @errno
%12 = load i64, i64* @EINTR
%13 = icmp eq i64 %11, %12
br label %14
14: ; preds = %10, %7
%15 = phi i1 [ false, %7 ], [ %13, %10 ]
br i1 %15, label %4, label %16
16: ; preds = %14
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @_pfatal(i32* null, i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@.str = [9 x i8] c"fd_close\00"
define void @fd_close(i32 %0) {
br label %2
2: ; preds = %2, %1
%3 = tail call i32 @close(i32 %0)
%4 = icmp eq i32 %3, -1
%5 = load i64, i64* @errno
%6 = load i64, i64* @EINTR
%7 = icmp eq i64 %5, %6
%8 = select i1 %4, i1 %7, i1 false
br i1 %8, label %2, label %9
9: ; preds = %2
%10 = icmp slt i32 %3, 0
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = tail call i32 @_pfatal(i32* null, i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %9
ret void
}