#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 EV_KEY;
int EV_SW;
int atoi(char *);
int /*<<< orphan*/ strncasecmp(char *, char *, int);
int translate_key_code(char *s, int *code, int *ev_type) {
  if (*s == 0)
    return -1;
  *code = 0;
  *ev_type = EV_KEY;
  if (!strncasecmp(s, "sw!", 3)) {
    s += 3;
    *ev_type = EV_SW;
  } else if (!strncasecmp(s, "key!", 3)) {
    s += 4;
    *ev_type = EV_KEY;
  }
  *code = atoi(s);
  return 0;
}


x86 assembly (clang, -O0):
<translate_key_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1150 <translate_key_code+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fd <translate_key_code+0xdd>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    0x2e7f(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe8c(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncasecmp@plt>
cmp    $0x0,%eax
jne    11a7 <translate_key_code+0x87>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    11e5 <translate_key_code+0xc5>
mov    -0x10(%rbp),%rdi
lea    0xe52(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncasecmp@plt>
cmp    $0x0,%eax
jne    11e0 <translate_key_code+0xc0>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    11e5 <translate_key_code+0xc5>
mov    -0x10(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<translate_key_code>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
je     117d <translate_key_code+0x5d>
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x0,(%rsi)
mov    0x2e9d(%rip),%r12
mov    (%r12),%eax
mov    %eax,(%rdx)
lea    0xeb0(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncasecmp@plt>
test   %eax,%eax
je     1184 <translate_key_code+0x64>
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <strncasecmp@plt>
test   %eax,%eax
jne    119a <translate_key_code+0x7a>
mov    $0x4,%eax
jmp    1190 <translate_key_code+0x70>
mov    $0xffffffff,%eax
jmp    11a7 <translate_key_code+0x87>
mov    0x2e5d(%rip),%r12
mov    $0x3,%eax
add    %rax,%rbx
mov    (%r12),%eax
mov    %eax,(%r15)
mov    %rbx,%rdi
call   1040 <atoi@plt>
mov    %eax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EV_KEY = global i32 0
@.str = [4 x i8] c"sw!\00"
@EV_SW = global i32 0
@.str.1 = [5 x i8] c"key!\00"
define i32 @translate_key_code(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%8 = load i8*, i8** %5
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %39
13: ; preds = %3
%14 = load i32*, i32** %6
store i32 0, i32* %14
%15 = load i32, i32* @EV_KEY
%16 = load i32*, i32** %7
store i32 %15, i32* %16
%17 = load i8*, i8** %5
%18 = call i32 @strncasecmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%19 = icmp ne i32 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %13
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 3
store i8* %22, i8** %5
%23 = load i32, i32* @EV_SW
%24 = load i32*, i32** %7
store i32 %23, i32* %24
br label %35
25: ; preds = %13
%26 = load i8*, i8** %5
%27 = call i32 @strncasecmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 3)
%28 = icmp ne i32 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %25
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 4
store i8* %31, i8** %5
%32 = load i32, i32* @EV_KEY
%33 = load i32*, i32** %7
store i32 %32, i32* %33
br label %34
34: ; preds = %29, %25
br label %35
35: ; preds = %34, %20
%36 = load i8*, i8** %5
%37 = call i32 @atoi(i8* %36)
%38 = load i32*, i32** %6
store i32 %37, i32* %38
store i32 0, i32* %4
br label %39
39: ; preds = %35, %12
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
@EV_KEY = global i32 0
@.str = [4 x i8] c"sw!\00"
@EV_SW = global i32 0
@.str.1 = [5 x i8] c"key!\00"
define i32 @translate_key_code(i8* nocapture %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %21, label %6
6: ; preds = %3
store i32 0, i32* %1
%7 = load i32, i32* @EV_KEY
store i32 %7, i32* %2
%8 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %10, %6
%14 = phi i64 [ 3, %6 ], [ 4, %10 ]
%15 = phi i32* [ @EV_SW, %6 ], [ @EV_KEY, %10 ]
%16 = getelementptr inbounds i8, i8* %0, i64 %14
%17 = load i32, i32* %15
store i32 %17, i32* %2
br label %18
18: ; preds = %13, %10
%19 = phi i8* [ %0, %10 ], [ %16, %13 ]
%20 = tail call i32 @atoi(i8* %19)
store i32 %20, i32* %1
br label %21
21: ; preds = %3, %18
%22 = phi i32 [ 0, %18 ], [ -1, %3 ]
ret i32 %22
}