#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 ioperm(int, int, int);
int /*<<< orphan*/ outb(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int strtol(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  int i;
  if (argc <= 1) {
    printf("Usage: send_to_keyboard <control codes>\n");
    printf("    e.g. send_to_keyboard ea 17\n");
  }
  if (ioperm(0x60, 3, 1) == -1)
    perror("Could not change port permissions. Please run as root.");
  for (i = 1; i < argc; i++) {
    int x = strtol(argv[i], 0, 16);
    usleep(300);
    outb(x, 0x60);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     1198 <main+0x38>
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
mov    $0x60,%edi
mov    $0x3,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
cmp    $0xffffffff,%eax
jne    11c1 <main+0x61>
lea    0xe8e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1214 <main+0xb4>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtol@plt>
mov    %eax,-0x18(%rbp)
mov    $0x12c,%edi
call   1080 <usleep@plt>
mov    -0x18(%rbp),%edi
mov    $0x60,%esi
call   1040 <outb@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c8 <main+0x68>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
cmp    $0x1,%edi
jg     1189 <main+0x29>
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
lea    0xedb(%rip),%rdi
call   1030 <puts@plt>
mov    $0x60,%edi
mov    $0x3,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
cmp    $0xffffffff,%eax
je     11ee <main+0x8e>
cmp    $0x2,%ebp
jl     11e1 <main+0x81>
mov    %ebp,%r15d
mov    $0x1,%ebx
nop
mov    (%r14,%rbx,8),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtol@plt>
mov    %eax,%ebp
mov    $0x12c,%edi
call   1080 <usleep@plt>
mov    %ebp,%edi
mov    $0x60,%esi
call   1040 <outb@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11b0 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe0b(%rip),%rdi
call   1070 <perror@plt>
cmp    $0x2,%ebp
jge    11a7 <main+0x47>
jmp    11e1 <main+0x81>

LLVM IR (-O0):
@.str = [41 x i8] c"Usage: send_to_keyboard <control codes>\0A\00"
@.str.1 = [33 x i8] c" e.g. send_to_keyboard ea 17\0A\00"
@.str.2 = [55 x i8] c"Could not change port permissions. Please run as root.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sle i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %10, %2
%14 = call i32 @ioperm(i32 96, i32 3, i32 1)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
store i32 1, i32* %6
br label %19
19: ; preds = %33, %18
%20 = load i32, i32* %6
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %36
23: ; preds = %19
%24 = load i8**, i8*** %5
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @strtol(i8* %28, i32 0, i32 16)
store i32 %29, i32* %7
%30 = call i32 @usleep(i32 300)
%31 = load i32, i32* %7
%32 = call i32 @outb(i32 %31, i32 96)
br label %33
33: ; preds = %23
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %19
36: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [55 x i8] c"Could not change port permissions. Please run as root.\00"
@str = [40 x i8] c"Usage: send_to_keyboard <control codes>\00"
@str.3 = [32 x i8] c" e.g. send_to_keyboard ea 17\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.3, i64 0, i64 0))
br label %7
7: ; preds = %4, %2
%8 = tail call i32 @ioperm(i32 96, i32 3, i32 1)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = icmp sgt i32 %0, 1
br i1 %13, label %14, label %25
14: ; preds = %12
%15 = zext i32 %0 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 1, %14 ], [ %23, %16 ]
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = tail call i32 @strtol(i8* %19, i32 0, i32 16)
%21 = tail call i32 @usleep(i32 300)
%22 = tail call i32 @outb(i32 %20, i32 96)
%23 = add nuw nsw i64 %17, 1
%24 = icmp eq i64 %23, %15
br i1 %24, label %25, label %16
25: ; preds = %16, %12
ret i32 0
}