#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 {
  int kb_index;
  int kb_table;
  int /*<<< orphan*/ kb_value;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ KDSKBENT;
int /*<<< orphan*/ K_HOLE;
int /*<<< orphan*/ K_NOSUCHMAP;
int MAX_NR_KEYMAPS;
int NR_KEYS;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int getfd(char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(void) {
  struct kbentry ke;
  int i, j, fd;
  char *console = NULL;
  fd = getfd(console);
  for (i = 0; i < MAX_NR_KEYMAPS; i++) {
    for (j = 0; j < NR_KEYS; j++) {
      ke.kb_index = j;
      ke.kb_table = i;
      ke.kb_value = K_HOLE;
      if (ioctl(fd, KDSKBENT, (unsigned long)&ke)) {
        perror("KDSKBENT");
        fprintf(stderr, "Error: cannot deallocate or clear keymap %d key %d\n",
                i, j);
        return EXIT_FAILURE;
      }
    }
    ke.kb_index = 0;
    ke.kb_table = i;
    ke.kb_value = K_NOSUCHMAP;
    if (ioctl(fd, KDSKBENT, (unsigned long)&ke)) {
      perror("KDSKBENT");
      fprintf(stderr, "Error: could not deallocate keymap %d\n", i);
      return EXIT_FAILURE;
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <getfd@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e44(%rip),%rcx
cmp    (%rcx),%eax
jge    129b <main+0x15b>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e53(%rip),%rcx
cmp    (%rcx),%eax
jge    1219 <main+0xd9>
mov    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
je     1206 <main+0xc6>
lea    0xe2d(%rip),%rdi
call   1050 <perror@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe1b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12a7 <main+0x167>
jmp    120b <main+0xcb>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1183 <main+0x43>
movl   $0x0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
je     1288 <main+0x148>
lea    0xda8(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12a7 <main+0x167>
jmp    128d <main+0x14d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116a <main+0x2a>
mov    0x2d06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %r15d,%r15d
xor    %edi,%edi
call   1060 <getfd@plt>
mov    %eax,%ebp
mov    0x2e57(%rip),%rcx
mov    0x2e40(%rip),%rax
cmpl   $0x0,(%rcx)
jle    1247 <main+0x107>
mov    0x2e68(%rip),%r12
mov    0x2e69(%rip),%r13
lea    0x8(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpl   $0x0,(%r12)
jle    11d2 <main+0x92>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %ebx,0x8(%rsp)
mov    %r15d,0xc(%rsp)
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x0(%r13),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
jne    1218 <main+0xd8>
add    $0x1,%ebx
cmp    (%r12),%ebx
jl     11a0 <main+0x60>
movl   $0x0,0x8(%rsp)
mov    %r15d,0xc(%rsp)
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x0(%r13),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
jne    1258 <main+0x118>
add    $0x1,%r15d
mov    0x2dae(%rip),%rax
cmp    (%rax),%r15d
jl     1190 <main+0x50>
mov    0x2d92(%rip),%rax
jmp    1247 <main+0x107>
lea    0xde1(%rip),%rdi
call   1050 <perror@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
mov    %r15d,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda1(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1240 <main+0x100>

LLVM IR (-O0):
%struct.kbentry = type { i32, i32, i32 }
@MAX_NR_KEYMAPS = global i32 0
@NR_KEYS = global i32 0
@K_HOLE = global i32 0
@KDSKBENT = global i32 0
@.str = [9 x i8] c"KDSKBENT\00"
@stderr = global i32 0
@.str.1 = [52 x i8] c"Error: cannot deallocate or clear keymap %d key %d\0A\00"
@EXIT_FAILURE = global i32 0
@K_NOSUCHMAP = global i32 0
@.str.2 = [39 x i8] c"Error: could not deallocate keymap %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.kbentry
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 0, i32* %1
store i8* null, i8** %6
%7 = load i8*, i8** %6
%8 = call i32 @getfd(i8* %7)
store i32 %8, i32* %5
store i32 0, i32* %3
br label %9
9: ; preds = %59, %0
%10 = load i32, i32* %3
%11 = load i32, i32* @MAX_NR_KEYMAPS
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %62
13: ; preds = %9
store i32 0, i32* %4
br label %14
14: ; preds = %38, %13
%15 = load i32, i32* %4
%16 = load i32, i32* @NR_KEYS
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %41
18: ; preds = %14
%19 = load i32, i32* %4
%20 = getelementptr inbounds %struct.kbentry, %struct.kbentry* %2, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* %3
%22 = getelementptr inbounds %struct.kbentry, %struct.kbentry* %2, i32 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* @K_HOLE
%24 = getelementptr inbounds %struct.kbentry, %struct.kbentry* %2, i32 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* %5
%26 = load i32, i32* @KDSKBENT
%27 = ptrtoint %struct.kbentry* %2 to i64
%28 = call i64 @ioctl(i32 %25, i32 %26, i64 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %18
%31 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%32 = load i32, i32* @stderr
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %34)
%36 = load i32, i32* @EXIT_FAILURE
store i32 %36, i32* %1
br label %64
37: ; preds = %18
br label %38
38: ; preds = %37
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %14
41: ; preds = %14
%42 = getelementptr inbounds %struct.kbentry, %struct.kbentry* %2, i32 0, i32 0
store i32 0, i32* %42
%43 = load i32, i32* %3
%44 = getelementptr inbounds %struct.kbentry, %struct.kbentry* %2, i32 0, i32 1
store i32 %43, i32* %44
%45 = load i32, i32* @K_NOSUCHMAP
%46 = getelementptr inbounds %struct.kbentry, %struct.kbentry* %2, i32 0, i32 2
store i32 %45, i32* %46
%47 = load i32, i32* %5
%48 = load i32, i32* @KDSKBENT
%49 = ptrtoint %struct.kbentry* %2 to i64
%50 = call i64 @ioctl(i32 %47, i32 %48, i64 %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %41
%53 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%54 = load i32, i32* @stderr
%55 = load i32, i32* %3
%56 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %55)
%57 = load i32, i32* @EXIT_FAILURE
store i32 %57, i32* %1
br label %64
58: ; preds = %41
br label %59
59: ; preds = %58
%60 = load i32, i32* %3
%61 = add nsw i32 %60, 1
store i32 %61, i32* %3
br label %9
62: ; preds = %9
%63 = load i32, i32* @EXIT_SUCCESS
store i32 %63, i32* %1
br label %64
64: ; preds = %62, %52, %30
%65 = load i32, i32* %1
ret i32 %65
}

LLVM IR (-O2):
%struct.kbentry = type { i32, i32, i32 }
@MAX_NR_KEYMAPS = global i32 0
@NR_KEYS = global i32 0
@K_HOLE = global i32 0
@KDSKBENT = global i32 0
@.str = [9 x i8] c"KDSKBENT\00"
@stderr = global i32 0
@.str.1 = [52 x i8] c"Error: cannot deallocate or clear keymap %d key %d\0A\00"
@EXIT_FAILURE = global i32 0
@K_NOSUCHMAP = global i32 0
@.str.2 = [39 x i8] c"Error: could not deallocate keymap %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.kbentry
%2 = bitcast %struct.kbentry* %1 to i8*
%3 = tail call i32 @getfd(i8* null)
%4 = load i32, i32* @MAX_NR_KEYMAPS
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %42
6: ; preds = %0
%7 = getelementptr inbounds %struct.kbentry, %struct.kbentry* %1, i64 0, i32 0
%8 = getelementptr inbounds %struct.kbentry, %struct.kbentry* %1, i64 0, i32 1
%9 = getelementptr inbounds %struct.kbentry, %struct.kbentry* %1, i64 0, i32 2
%10 = ptrtoint %struct.kbentry* %1 to i64
br label %11
11: ; preds = %6, %38
%12 = phi i32 [ 0, %6 ], [ %39, %38 ]
%13 = load i32, i32* @NR_KEYS
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %11, %25
%16 = phi i32 [ %26, %25 ], [ 0, %11 ]
store i32 %16, i32* %7
store i32 %12, i32* %8
%17 = load i32, i32* @K_HOLE
store i32 %17, i32* %9
%18 = load i32, i32* @KDSKBENT
%19 = call i64 @ioctl(i32 %3, i32 %18, i64 %10)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %15
%22 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %16)
br label %42
25: ; preds = %15
%26 = add nuw nsw i32 %16, 1
%27 = load i32, i32* @NR_KEYS
%28 = icmp slt i32 %26, %27
br i1 %28, label %15, label %29
29: ; preds = %25, %11
store i32 0, i32* %7
store i32 %12, i32* %8
%30 = load i32, i32* @K_NOSUCHMAP
store i32 %30, i32* %9
%31 = load i32, i32* @KDSKBENT
%32 = call i64 @ioctl(i32 %3, i32 %31, i64 %10)
%33 = icmp eq i64 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %29
%35 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %42
38: ; preds = %29
%39 = add nuw nsw i32 %12, 1
%40 = load i32, i32* @MAX_NR_KEYMAPS
%41 = icmp slt i32 %39, %40
br i1 %41, label %11, label %42
42: ; preds = %38, %0, %34, %21
%43 = phi i32* [ @EXIT_FAILURE, %21 ], [ @EXIT_FAILURE, %34 ], [ @EXIT_SUCCESS, %0 ], [ @EXIT_SUCCESS, %38 ]
%44 = load i32, i32* %43
ret i32 %44
}