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


x86 assembly (clang, -O0):
<disk_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11c0 <disk_open+0x90>
mov    0x2e74(%rip),%rax
mov    (%rax),%rax
mov    0x2e62(%rip),%rcx
cmp    (%rcx),%rax
jne    117c <disk_open+0x4c>
jmp    11c5 <disk_open+0x95>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe4a(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11c5 <disk_open+0x95>
jmp    11c5 <disk_open+0x95>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disk_open>:
push   %rbp
push   %r14
push   %rbx
call   1040 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    117b <disk_open+0x4b>
mov    0x2e91(%rip),%rax
mov    (%rax),%r14
mov    0x2e7f(%rip),%rax
cmp    (%rax),%r14
je     117b <disk_open+0x4b>
mov    0x2e83(%rip),%rax
mov    (%rax),%ebp
mov    %r14,%rdi
call   1050 <strerror@plt>
lea    0xe92(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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