#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;
scalar_t__ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__, char *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int disk_close(int fd) {
  do {
    if (close(fd) != 0) {
      if (errno == EINTR)
        continue;
      fprintf(stderr, "disk close error (%d:%s)\n", errno, strerror(errno));
      return -1;
    }
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<disk_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
cmp    $0x0,%rax
je     11b7 <disk_close+0x87>
mov    0x2e84(%rip),%rax
mov    (%rax),%rax
mov    0x2e72(%rip),%rcx
cmp    (%rcx),%rax
jne    116c <disk_close+0x3c>
jmp    11bc <disk_close+0x8c>
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rdx
mov    %rax,%rcx
lea    0xe5a(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <disk_close+0x93>
jmp    11bc <disk_close+0x8c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disk_close>:
push   %rbp
push   %rbx
push   %rax
call   1030 <close@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     1182 <disk_close+0x52>
mov    0x2e8f(%rip),%rcx
mov    (%rcx),%rbx
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%rbx
je     1182 <disk_close+0x52>
mov    0x2e81(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1050 <strerror@plt>
lea    0xe90(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str = [26 x i8] c"disk close error (%d:%s)\0A\00"
define i32 @disk_close(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
br label %4
4: ; preds = %1
%5 = load i32, i32* %3
%6 = call i64 @close(i32 %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %19
8: ; preds = %4
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINTR
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %8
br label %20
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i64, i64* @errno
%16 = load i64, i64* @errno
%17 = call i8* @strerror(i64 %16)
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %15, i8* %17)
store i32 -1, i32* %2
br label %21
19: ; preds = %4
br label %20
20: ; preds = %12, %19
store i32 0, i32* %2
br label %21
21: ; preds = %20, %13
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str = [26 x i8] c"disk close error (%d:%s)\0A\00"
define i32 @disk_close(i32 %0) {
%2 = tail call i64 @close(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = load i64, i64* @errno
%6 = load i64, i64* @EINTR
%7 = icmp eq i64 %5, %6
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = tail call i8* @strerror(i64 %5)
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %5, i8* %10)
br label %12
12: ; preds = %4, %1, %8
%13 = phi i32 [ -1, %8 ], [ 0, %1 ], [ 0, %4 ]
ret i32 %13
}