#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 */
struct timespec {
  int tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int ioctl(int, int, void *);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int lfc_ioctl(int fd, int req, void *arg) {
  struct timespec poll_time;
  int r;
  while (r = ioctl(fd, req, arg), r == -1 && EINTR == errno) {
    poll_time.tv_sec = 0;
    poll_time.tv_nsec = 10000000;
    nanosleep(&poll_time, NULL);
  }
  return r;
}


x86 assembly (clang, -O0):
<lfc_ioctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x24(%rbp)
mov    %al,-0x25(%rbp)
jne    116d <lfc_ioctl+0x4d>
mov    0x2e7e(%rip),%rax
mov    (%rax),%rax
mov    0x2e7c(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    117d <lfc_ioctl+0x5d>
jmp    119e <lfc_ioctl+0x7e>
movq   $0x0,-0x18(%rbp)
movl   $0x989680,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <nanosleep@plt>
jmp    1132 <lfc_ioctl+0x12>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lfc_ioctl>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %edi,%ebx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1196 <lfc_ioctl+0x76>
mov    0x2e92(%rip),%r12
mov    0x2e93(%rip),%r13
mov    0x0(%r13),%rcx
cmp    %rcx,(%r12)
jne    1196 <lfc_ioctl+0x76>
lea    0x8(%rsp),%r15
nopl   0x0(%rax)
movq   $0x0,0x10(%rsp)
movl   $0x989680,0x8(%rsp)
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r14,%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1196 <lfc_ioctl+0x76>
mov    0x0(%r13),%rcx
cmp    %rcx,(%r12)
je     1160 <lfc_ioctl+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@EINTR = global i64 0
@errno = global i64 0
define i32 @lfc_ioctl(i32 %0, i32 %1, i8* %2) {
%4 = alloca %struct.timespec
%5 = bitcast %struct.timespec* %4 to i8*
%6 = call i32 @ioctl(i32 %0, i32 %1, i8* %2)
%7 = icmp eq i32 %6, -1
%8 = load i64, i64* @EINTR
%9 = load i64, i64* @errno
%10 = icmp eq i64 %8, %9
%11 = select i1 %7, i1 %10, i1 false
br i1 %11, label %12, label %23
12: ; preds = %3
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
br label %15
15: ; preds = %12, %15
store i64 0, i64* %13
store i32 10000000, i32* %14
%16 = call i32 @nanosleep(%struct.timespec* %4, i32* null)
%17 = call i32 @ioctl(i32 %0, i32 %1, i8* %2)
%18 = icmp eq i32 %17, -1
%19 = load i64, i64* @EINTR
%20 = load i64, i64* @errno
%21 = icmp eq i64 %19, %20
%22 = select i1 %18, i1 %21, i1 false
br i1 %22, label %15, label %23
23: ; preds = %15, %3
%24 = phi i32 [ %6, %3 ], [ %17, %15 ]
ret i32 %24
}