#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 */
int errno;
scalar_t__ ioctl(int, int, int);
int /*<<< orphan*/ printf(char *, char *, ...);
char *strerror(int);
void selectDevice(int fd, int addr, char *name) {
  if (ioctl(fd, 0x0703, addr) < 0) {
    printf("%s not present\n", name);
    printf("error: %s (%d)\n", strerror(errno), errno);
  }
}


x86 assembly (clang, -O0):
<selectDevice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%edx
mov    $0x703,%esi
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1196 <selectDevice+0x66>
mov    -0x10(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<selectDevice>:
push   %rbx
mov    %rdx,%rbx
mov    %esi,%edx
mov    $0x703,%esi
call   1040 <ioctl@plt>
test   %rax,%rax
js     1147 <selectDevice+0x17>
pop    %rbx
ret
lea    0xeb2(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e81(%rip),%rbx
mov    (%rbx),%edi
call   1050 <strerror@plt>
mov    (%rbx),%edx
lea    0xea1(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"%s not present\0A\00"
@.str.1 = [16 x i8] c"error: %s (%d)\0A\00"
@errno = global i32 0
define void @selectDevice(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%7 = load i32, i32* %4
%8 = load i32, i32* %5
%9 = call i64 @ioctl(i32 %7, i32 1795, i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %3
%12 = load i8*, i8** %6
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = load i32, i32* @errno
%17 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32 %16)
br label %18
18: ; preds = %11, %3
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"%s not present\0A\00"
@.str.1 = [16 x i8] c"error: %s (%d)\0A\00"
@errno = global i32 0
define void @selectDevice(i32 %0, i32 %1, i8* %2) {
%4 = tail call i64 @ioctl(i32 %0, i32 1795, i32 %1)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %2)
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = load i32, i32* @errno
%11 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32 %10)
br label %12
12: ; preds = %6, %3
ret void
}