#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*/ strcpy(char *, char *);
int getregstr(char *regstr, int reg) {
  switch (reg) {
  case 1:
    strcpy(regstr, "eax");
    return 0;
  case 2:
    strcpy(regstr, "ebx");
    return 0;
  case 3:
    strcpy(regstr, "ecx");
    return 0;
  case 4:
    strcpy(regstr, "edx");
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<getregstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     11b8 <getregstr+0xa8>
mov    -0x20(%rbp),%rax
lea    0xec1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
lea    0xebd(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    11bf <getregstr+0xaf>
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    11bf <getregstr+0xaf>
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    11bf <getregstr+0xaf>
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    11bf <getregstr+0xaf>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getregstr>:
add    $0xffffffff,%esi
mov    $0xffffffff,%eax
cmp    $0x3,%esi
ja     113a <getregstr+0x2a>
push   %rax
movslq %esi,%rax
lea    0xee8(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"eax\00"
@.str.1 = [4 x i8] c"ebx\00"
@.str.2 = [4 x i8] c"ecx\00"
@.str.3 = [4 x i8] c"edx\00"
define i32 @getregstr(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
switch i32 %6, label %19 [
i32 1, label %7
i32 2, label %10
i32 3, label %13
i32 4, label %16
]
7: ; preds = %2
%8 = load i8*, i8** %4
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %20
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %20
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %20
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %20
19: ; preds = %2
store i32 -1, i32* %3
br label %20
20: ; preds = %19, %16, %13, %10, %7
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@.str = [4 x i8] c"eax\00"
@.str.1 = [4 x i8] c"ebx\00"
@.str.2 = [4 x i8] c"ecx\00"
@.str.3 = [4 x i8] c"edx\00"
@reltable.getregstr = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @reltable.getregstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.getregstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.getregstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.getregstr to i64)) to i32)]
define i32 @getregstr(i8* %0, i32 %1) {
%3 = add i32 %1, -1
%4 = icmp ult i32 %3, 4
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = sext i32 %3 to i64
%7 = shl i64 %6, 2
%8 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.getregstr to i8*), i64 %7)
%9 = tail call i32 @strcpy(i8* %0, i8* %8)
br label %10
10: ; preds = %2, %5
%11 = phi i32 [ -1, %2 ], [ 0, %5 ]
ret i32 %11
}