#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__ EAGAIN;
scalar_t__ EINTR;
scalar_t__ errno;
int ioctl(int, unsigned long, void *);
int kmtIoctl(int fd, unsigned long request, void *arg) {
  int ret;
  do {
    ret = ioctl(fd, request, arg);
  } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
  return ret;
}


x86 assembly (clang, -O0):
<kmtIoctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
jne    1184 <kmtIoctl+0x74>
mov    0x2e94(%rip),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x2e80(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x1e(%rbp)
je     117e <kmtIoctl+0x6e>
mov    0x2e75(%rip),%rax
mov    (%rax),%rax
mov    0x2e53(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1123 <kmtIoctl+0x13>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kmtIoctl>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2eb6(%rip),%r15
mov    0x2ea7(%rip),%r12
mov    0x2e90(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1161 <kmtIoctl+0x51>
mov    (%r15),%rcx
cmp    (%r12),%rcx
je     1140 <kmtIoctl+0x30>
cmp    0x0(%r13),%rcx
je     1140 <kmtIoctl+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@EAGAIN = global i64 0
define i32 @kmtIoctl(i32 %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i64 %1, i64* %5
store i8* %2, i8** %6
br label %8
8: ; preds = %26, %3
%9 = load i32, i32* %4
%10 = load i64, i64* %5
%11 = load i8*, i8** %6
%12 = call i32 @ioctl(i32 %9, i64 %10, i8* %11)
store i32 %12, i32* %7
br label %13
13: ; preds = %8
%14 = load i32, i32* %7
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i64, i64* @errno
%18 = load i64, i64* @EINTR
%19 = icmp eq i64 %17, %18
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = load i64, i64* @errno
%22 = load i64, i64* @EAGAIN
%23 = icmp eq i64 %21, %22
br label %24
24: ; preds = %20, %16
%25 = phi i1 [ true, %16 ], [ %23, %20 ]
br label %26
26: ; preds = %24, %13
%27 = phi i1 [ false, %13 ], [ %25, %24 ]
br i1 %27, label %8, label %28
28: ; preds = %26
%29 = load i32, i32* %7
ret i32 %29
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@EAGAIN = global i64 0
define i32 @kmtIoctl(i32 %0, i64 %1, i8* %2) {
br label %4
4: ; preds = %7, %3
%5 = tail call i32 @ioctl(i32 %0, i64 %1, i8* %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = load i64, i64* @errno
%9 = load i64, i64* @EINTR
%10 = icmp eq i64 %8, %9
%11 = load i64, i64* @EAGAIN
%12 = icmp eq i64 %8, %11
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %4, label %14
14: ; preds = %4, %7
ret i32 %5
}