#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ UI_SET_KEYBIT;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
void set_keybit(int fd, int bit) {
  if (ioctl(fd, UI_SET_KEYBIT, bit) < 0)
    do {
      fprintf(stderr, "ERROR: ");
      fprintf(stderr, "Could not set KEYBIT %i", bit);
      fprintf(stderr, "\n");
      exit(EXIT_FAILURE);
    } while (0);
}


x86 assembly (clang, -O0):
<set_keybit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11b7 <set_keybit+0x87>
jmp    1161 <set_keybit+0x31>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_keybit>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edx
call   1030 <ioctl@plt>
test   %rax,%rax
js     1153 <set_keybit+0x23>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e7e(%rip),%r14
mov    (%r14),%edi
lea    0xe9c(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
lea    0xe93(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
lea    0xe98(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@UI_SET_KEYBIT = global i32 0
@stderr = global i32 0
@.str = [8 x i8] c"ERROR: \00"
@.str.1 = [24 x i8] c"Could not set KEYBIT %i\00"
@.str.2 = [2 x i8] c"\0A\00"
@EXIT_FAILURE = global i32 0
define void @set_keybit(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %3
%6 = load i32, i32* @UI_SET_KEYBIT
%7 = load i32, i32* %4
%8 = call i64 @ioctl(i32 %5, i32 %6, i32 %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %22
10: ; preds = %2
br label %11
11: ; preds = %10
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @stderr
%15 = load i32, i32* %4
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; No predecessors!
br label %22
22: ; preds = %21, %2
ret void
}

LLVM IR (-O2):
@UI_SET_KEYBIT = global i32 0
@stderr = global i32 0
@.str = [8 x i8] c"ERROR: \00"
@.str.1 = [24 x i8] c"Could not set KEYBIT %i\00"
@.str.2 = [2 x i8] c"\0A\00"
@EXIT_FAILURE = global i32 0
define void @set_keybit(i32 %0, i32 %1) {
%3 = load i32, i32* @UI_SET_KEYBIT
%4 = tail call i64 @ioctl(i32 %0, i32 %3, i32 %1)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
ret void
}