#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 lookup_key(char *);
int sscanf(char *, char *, int *);
int strlen(char *);
int parse_key(char *value, int *key) {
  int temp;
  if (value[0] == '\'' && value[2] == '\'' && strlen(value) == 3) {
    *key = (int)value[1];
    return 0;
  }
  if ((temp = lookup_key(value)) != -1) {
    *key = temp;
    return 0;
  }
  if (sscanf(value, "%d", &temp) == 1) {
    *key = temp;
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<parse_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
jne    118d <parse_key+0x5d>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x27,%eax
jne    118d <parse_key+0x5d>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x3,%eax
jne    118d <parse_key+0x5d>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11f0 <parse_key+0xc0>
mov    -0x10(%rbp),%rdi
call   1040 <lookup_key@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     11b7 <parse_key+0x87>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11f0 <parse_key+0xc0>
mov    -0x10(%rbp),%rdi
lea    0xe3e(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11e9 <parse_key+0xb9>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11f0 <parse_key+0xc0>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_key>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
cmpb   $0x27,(%rdi)
jne    1158 <parse_key+0x28>
cmpb   $0x27,0x2(%rbx)
jne    1158 <parse_key+0x28>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x3,%eax
jne    1158 <parse_key+0x28>
movsbl 0x1(%rbx),%eax
jmp    118d <parse_key+0x5d>
mov    %rbx,%rdi
call   1040 <lookup_key@plt>
mov    %eax,0x4(%rsp)
cmp    $0xffffffff,%eax
jne    118d <parse_key+0x5d>
lea    0xe90(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x1,%ecx
jne    1192 <parse_key+0x62>
mov    0x4(%rsp),%eax
mov    %eax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @parse_key(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 39
br i1 %6, label %7, label %18
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %0, i64 2
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 39
br i1 %10, label %11, label %18
11: ; preds = %7
%12 = tail call i32 @strlen(i8* %0)
%13 = icmp eq i32 %12, 3
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %0, i64 1
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
br label %26
18: ; preds = %11, %7, %2
%19 = tail call i32 @lookup_key(i8* %0)
store i32 %19, i32* %3
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* %3
br label %26
26: ; preds = %18, %14, %24
%27 = phi i32 [ %25, %24 ], [ %17, %14 ], [ %19, %18 ]
store i32 %27, i32* %1
br label %28
28: ; preds = %26, %21
%29 = phi i32 [ 1, %21 ], [ 0, %26 ]
ret i32 %29
}