#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 /*<<< orphan*/ sprintf(char *, char *, int);
char *button(int code) {
  static char n[10];
  sprintf(n, "%d", code);
  switch (code) {
  case 272:
    return "left";
    break;
  case 273:
    return "right";
    break;
  case 274:
    return "middle";
    break;
  default:
    return n;
  }
}


x86 assembly (clang, -O0):
<button>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edx
lea    0x2f04(%rip),%rdi
lea    0xed4(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x110,%eax
je     116d <button+0x5d>
jmp    1147 <button+0x37>
mov    -0x10(%rbp),%eax
sub    $0x111,%eax
je     117d <button+0x6d>
jmp    115a <button+0x4a>
mov    -0x10(%rbp),%eax
sub    $0x112,%eax
je     118d <button+0x7d>
jmp    119d <button+0x8d>
lea    0xe8f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a8 <button+0x98>
lea    0xe84(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a8 <button+0x98>
lea    0xe7a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a8 <button+0x98>
lea    0x2e85(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<button>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0x2f0d(%rip),%rbx
lea    0xedd(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <sprintf@plt>
add    $0xfffffef0,%ebp
cmp    $0x2,%ebp
ja     1149 <button+0x39>
movslq %ebp,%rax
lea    0xed6(%rip),%rcx
movslq (%rcx,%rax,4),%rbx
add    %rcx,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@button.n = internal global [10 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"left\00"
@.str.2 = [6 x i8] c"right\00"
@.str.3 = [7 x i8] c"middle\00"
define i8* @button(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = call i32 @sprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @button.n, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* %3
switch i32 %6, label %10 [
i32 272, label %7
i32 273, label %8
i32 274, label %9
]
7: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %11
8: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %11
9: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %11
10: ; preds = %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @button.n, i64 0, i64 0), i8** %2
br label %11
11: ; preds = %10, %9, %8, %7
%12 = load i8*, i8** %2
ret i8* %12
}

LLVM IR (-O2):
@button.n = internal global [10 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"left\00"
@.str.2 = [6 x i8] c"right\00"
@.str.3 = [7 x i8] c"middle\00"
@reltable.button = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.button to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.button to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.3 to i64), i64 ptrtoint ([3 x i32]* @reltable.button to i64)) to i32)]
define i8* @button(i32 %0) {
%2 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @button.n, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = add i32 %0, -272
%4 = icmp ult i32 %3, 3
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = sext i32 %3 to i64
%7 = shl i64 %6, 2
%8 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.button to i8*), i64 %7)
br label %9
9: ; preds = %1, %5
%10 = phi i8* [ %8, %5 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @button.n, i64 0, i64 0), %1 ]
ret i8* %10
}