#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 kbentry {
  char kb_index;
  char kb_table;
  int kb_value;
};

/* Variables and functions */
int /*<<< orphan*/ FBerror(int, char *, char, char);
int /*<<< orphan*/ KDGKBENT;
scalar_t__ ioctl(int, int /*<<< orphan*/, struct kbentry *);
int translate_key(int fd, char table, char index) {
  struct kbentry ke;
  ke.kb_index = index;
  ke.kb_table = table;
  if (ioctl(fd, KDGKBENT, &ke)) {
    FBerror(0x0001 | 0x0002, "KDGKBENT at index %d in table %d: ", index,
            table);
  }
  return ke.kb_value;
}


x86 assembly (clang, -O0):
<translate_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %edi,-0x4(%rbp)
mov    %cl,-0x5(%rbp)
mov    %al,-0x6(%rbp)
mov    -0x6(%rbp),%al
mov    %al,-0x10(%rbp)
mov    -0x5(%rbp),%al
mov    %al,-0xf(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
je     117c <translate_key+0x5c>
mov    -0x6(%rbp),%al
mov    $0x3,%edi
lea    0xe90(%rip),%rsi
movsbl %al,%edx
movsbl -0x5(%rbp),%ecx
call   1040 <FBerror@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<translate_key>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%ebx
mov    %bpl,(%rsp)
mov    %bl,0x1(%rsp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
je     115d <translate_key+0x3d>
movsbl %bpl,%edx
movsbl %bl,%ecx
lea    0xead(%rip),%rsi
mov    $0x3,%edi
call   1040 <FBerror@plt>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.kbentry = type { i8, i8, i32 }
@KDGKBENT = global i32 0
@.str = [35 x i8] c"KDGKBENT at index %d in table %d: \00"
define i32 @translate_key(i32 %0, i8 signext %1, i8 signext %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
%7 = alloca %struct.kbentry
store i32 %0, i32* %4
store i8 %1, i8* %5
store i8 %2, i8* %6
%8 = load i8, i8* %6
%9 = getelementptr inbounds %struct.kbentry, %struct.kbentry* %7, i32 0, i32 0
store i8 %8, i8* %9
%10 = load i8, i8* %5
%11 = getelementptr inbounds %struct.kbentry, %struct.kbentry* %7, i32 0, i32 1
store i8 %10, i8* %11
%12 = load i32, i32* %4
%13 = load i32, i32* @KDGKBENT
%14 = call i64 @ioctl(i32 %12, i32 %13, %struct.kbentry* %7)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i8, i8* %6
%18 = load i8, i8* %5
%19 = call i32 @FBerror(i32 3, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8 signext %17, i8 signext %18)
br label %20
20: ; preds = %16, %3
%21 = getelementptr inbounds %struct.kbentry, %struct.kbentry* %7, i32 0, i32 2
%22 = load i32, i32* %21
ret i32 %22
}

LLVM IR (-O2):
%struct.kbentry = type { i8, i8, i32 }
@KDGKBENT = global i32 0
@.str = [35 x i8] c"KDGKBENT at index %d in table %d: \00"
define i32 @translate_key(i32 %0, i8 signext %1, i8 signext %2) {
%4 = alloca %struct.kbentry
%5 = getelementptr inbounds %struct.kbentry, %struct.kbentry* %4, i64 0, i32 0
store i8 %2, i8* %5
%6 = getelementptr inbounds %struct.kbentry, %struct.kbentry* %4, i64 0, i32 1
store i8 %1, i8* %6
%7 = load i32, i32* @KDGKBENT
%8 = call i64 @ioctl(i32 %0, i32 %7, %struct.kbentry* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %3
%11 = call i32 @FBerror(i32 3, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8 signext %2, i8 signext %1)
br label %12
12: ; preds = %10, %3
%13 = getelementptr inbounds %struct.kbentry, %struct.kbentry* %4, i64 0, i32 2
%14 = load i32, i32* %13
ret i32 %14
}