#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 dasm_read_imm_16(int);
int dasm_read_imm_32(int);
int dasm_read_imm_8(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *get_imm_str_u(unsigned int size) {
  static char str[15];
  if (size == 0)
    sprintf(str, "#$%x", dasm_read_imm_8(2) & 0xff);
  else if (size == 1)
    sprintf(str, "#$%x", dasm_read_imm_16(2) & 0xffff);
  else
    sprintf(str, "#$%x", dasm_read_imm_32(4) & 0xffffffff);
  return str;
}


x86 assembly (clang, -O0):
<get_imm_str_u>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    117f <get_imm_str_u+0x3f>
mov    $0x2,%edi
call   1030 <dasm_read_imm_8@plt>
mov    %eax,%edx
and    $0xff,%edx
lea    0x2ed3(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <sprintf@plt>
jmp    11da <get_imm_str_u+0x9a>
cmpl   $0x1,-0x4(%rbp)
jne    11b3 <get_imm_str_u+0x73>
mov    $0x2,%edi
call   1040 <dasm_read_imm_16@plt>
mov    %eax,%edx
and    $0xffff,%edx
lea    0x2e9f(%rip),%rdi
lea    0xe57(%rip),%rsi
call   1060 <sprintf@plt>
jmp    11d5 <get_imm_str_u+0x95>
mov    $0x4,%edi
call   1050 <dasm_read_imm_32@plt>
mov    %eax,%edx
and    $0xffffffff,%edx
lea    0x2e78(%rip),%rdi
lea    0xe30(%rip),%rsi
call   1060 <sprintf@plt>
jmp    11da <get_imm_str_u+0x9a>
lea    0x2e60(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_imm_str_u>:
push   %rbx
cmp    $0x1,%edi
je     1159 <get_imm_str_u+0x19>
test   %edi,%edi
jne    1168 <get_imm_str_u+0x28>
mov    $0x2,%edi
call   1030 <dasm_read_imm_8@plt>
movzbl %al,%edx
jmp    1174 <get_imm_str_u+0x34>
mov    $0x2,%edi
call   1040 <dasm_read_imm_16@plt>
movzwl %ax,%edx
jmp    1174 <get_imm_str_u+0x34>
mov    $0x4,%edi
call   1050 <dasm_read_imm_32@plt>
mov    %eax,%edx
lea    0x2ec6(%rip),%rbx
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@get_imm_str_u.str = internal global [15 x i8] zeroinitializer
@.str = [5 x i8] c"#$%x\00"
define i8* @get_imm_str_u(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = call i32 @dasm_read_imm_8(i32 2)
%7 = and i32 %6, 255
%8 = call i32 @sprintf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @get_imm_str_u.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %21
9: ; preds = %1
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = call i32 @dasm_read_imm_16(i32 2)
%14 = and i32 %13, 65535
%15 = call i32 @sprintf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @get_imm_str_u.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %20
16: ; preds = %9
%17 = call i32 @dasm_read_imm_32(i32 4)
%18 = and i32 %17, -1
%19 = call i32 @sprintf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @get_imm_str_u.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16, %12
br label %21
21: ; preds = %20, %5
ret i8* getelementptr inbounds ([15 x i8], [15 x i8]* @get_imm_str_u.str, i64 0, i64 0)
}

LLVM IR (-O2):
@get_imm_str_u.str = internal global [15 x i8] zeroinitializer
@.str = [5 x i8] c"#$%x\00"
define i8* @get_imm_str_u(i32 %0) {
switch i32 %0, label %8 [
i32 0, label %2
i32 1, label %5
]
2: ; preds = %1
%3 = tail call i32 @dasm_read_imm_8(i32 2)
%4 = and i32 %3, 255
br label %10
5: ; preds = %1
%6 = tail call i32 @dasm_read_imm_16(i32 2)
%7 = and i32 %6, 65535
br label %10
8: ; preds = %1
%9 = tail call i32 @dasm_read_imm_32(i32 4)
br label %10
10: ; preds = %5, %8, %2
%11 = phi i32 [ %7, %5 ], [ %9, %8 ], [ %4, %2 ]
%12 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @get_imm_str_u.str, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %11)
ret i8* getelementptr inbounds ([15 x i8], [15 x i8]* @get_imm_str_u.str, i64 0, i64 0)
}