#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__ EBUSY;
scalar_t__ EINVAL;
scalar_t__ ENODEV;
scalar_t__ errno;
int ioctl(int, int, char *);
int ioctlWrapper(int fd, int ionum) {
  char buffer[100];
  int r = ioctl(fd, ionum, buffer);
  if (r) {
    if (errno == EINVAL)
      return -100;
    else if (errno == EBUSY)
      return -20;
    else if (errno == ENODEV)
      return -5;
    return -99;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ioctlWrapper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    -0x70(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
je     11c5 <ioctlWrapper+0xb5>
mov    0x2e9c(%rip),%rax
mov    (%rax),%rax
mov    0x2e8a(%rip),%rcx
cmp    (%rcx),%rax
jne    1163 <ioctlWrapper+0x53>
movl   $0xffffff9c,-0x4(%rbp)
jmp    11cc <ioctlWrapper+0xbc>
mov    0x2e76(%rip),%rax
mov    (%rax),%rax
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%rax
jne    1189 <ioctlWrapper+0x79>
movl   $0xffffffec,-0x4(%rbp)
jmp    11cc <ioctlWrapper+0xbc>
mov    0x2e50(%rip),%rax
mov    (%rax),%rax
mov    0x2e2e(%rip),%rcx
cmp    (%rcx),%rax
jne    11af <ioctlWrapper+0x9f>
movl   $0xfffffffb,-0x4(%rbp)
jmp    11cc <ioctlWrapper+0xbc>
jmp    11b4 <ioctlWrapper+0xa4>
jmp    11b9 <ioctlWrapper+0xa9>
movl   $0xffffff9d,-0x4(%rbp)
jmp    11cc <ioctlWrapper+0xbc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ioctlWrapper>:
sub    $0x68,%rsp
mov    %rsp,%rdx
call   1030 <ioctl@plt>
test   %eax,%eax
je     1168 <ioctlWrapper+0x58>
mov    0x2eb9(%rip),%rax
mov    (%rax),%rcx
mov    0x2ea7(%rip),%rdx
mov    $0xffffff9c,%eax
cmp    (%rdx),%rcx
je     1163 <ioctlWrapper+0x53>
mov    0x2e8e(%rip),%rdx
mov    $0xffffffec,%eax
cmp    (%rdx),%rcx
je     1163 <ioctlWrapper+0x53>
mov    0x2e75(%rip),%rax
cmp    (%rax),%rcx
mov    $0xfffffffb,%ecx
mov    $0xffffff9d,%eax
cmove  %ecx,%eax
add    $0x68,%rsp
ret
xor    %eax,%eax
add    $0x68,%rsp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINVAL = global i64 0
@EBUSY = global i64 0
@ENODEV = global i64 0
define i32 @ioctlWrapper(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [100 x i8]
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = load i32, i32* %5
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%11 = call i32 @ioctl(i32 %8, i32 %9, i8* %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %32
14: ; preds = %2
%15 = load i64, i64* @errno
%16 = load i64, i64* @EINVAL
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 -100, i32* %3
br label %33
19: ; preds = %14
%20 = load i64, i64* @errno
%21 = load i64, i64* @EBUSY
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 -20, i32* %3
br label %33
24: ; preds = %19
%25 = load i64, i64* @errno
%26 = load i64, i64* @ENODEV
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 -5, i32* %3
br label %33
29: ; preds = %24
br label %30
30: ; preds = %29
br label %31
31: ; preds = %30
store i32 -99, i32* %3
br label %33
32: ; preds = %2
store i32 0, i32* %3
br label %33
33: ; preds = %32, %31, %28, %23, %18
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@errno = global i64 0
@EINVAL = global i64 0
@EBUSY = global i64 0
@ENODEV = global i64 0
define i32 @ioctlWrapper(i32 %0, i32 %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = call i32 @ioctl(i32 %0, i32 %1, i8* %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %18, label %7
7: ; preds = %2
%8 = load i64, i64* @errno
%9 = load i64, i64* @EINVAL
%10 = icmp eq i64 %8, %9
br i1 %10, label %18, label %11
11: ; preds = %7
%12 = load i64, i64* @EBUSY
%13 = icmp eq i64 %8, %12
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = load i64, i64* @ENODEV
%16 = icmp eq i64 %8, %15
%17 = select i1 %16, i32 -5, i32 -99
br label %18
18: ; preds = %2, %14, %11, %7
%19 = phi i32 [ -100, %7 ], [ -20, %11 ], [ %17, %14 ], [ 0, %2 ]
ret i32 %19
}