#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*/ Port_Puts(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
void Port_itoa(int value, char *str, int radix) {
  if (radix == 10) {
    sprintf(str, "%d", value);
  } else if (radix == 16) {
    sprintf(str, "%X", value);
  } else {
    Port_Puts(0, "Port_itoa (Port.c)", "Unsupported base! Fix this!");
  }
  return;
}


x86 assembly (clang, -O0):
<Port_itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jne    1154 <Port_itoa+0x34>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xeb6(%rip),%rsi
call   1040 <sprintf@plt>
jmp    1190 <Port_itoa+0x70>
cmpl   $0x10,-0x14(%rbp)
jne    1176 <Port_itoa+0x56>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe97(%rip),%rsi
call   1040 <sprintf@plt>
jmp    118b <Port_itoa+0x6b>
xor    %edi,%edi
lea    0xe87(%rip),%rsi
lea    0xe93(%rip),%rdx
call   1030 <Port_Puts@plt>
jmp    1190 <Port_itoa+0x70>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Port_itoa>:
mov    %edi,%eax
cmp    $0x10,%edx
je     1135 <Port_itoa+0x15>
cmp    $0xa,%edx
jne    1149 <Port_itoa+0x29>
lea    0xecd(%rip),%rcx
jmp    113c <Port_itoa+0x1c>
lea    0xec7(%rip),%rcx
mov    %rsi,%rdi
mov    %rcx,%rsi
mov    %eax,%edx
jmp    1040 <sprintf@plt>
lea    0xeb6(%rip),%rsi
lea    0xec2(%rip),%rdx
xor    %edi,%edi
jmp    1030 <Port_Puts@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%X\00"
@.str.2 = [19 x i8] c"Port_itoa (Port.c)\00"
@.str.3 = [28 x i8] c"Unsupported base! Fix this!\00"
define void @Port_itoa(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = icmp eq i32 %7, 10
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = load i8*, i8** %5
%11 = load i32, i32* %4
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %23
13: ; preds = %3
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 16
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i8*, i8** %5
%18 = load i32, i32* %4
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %22
20: ; preds = %13
%21 = call i32 @Port_Puts(i32 0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
br label %23
23: ; preds = %22, %9
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%X\00"
@.str.2 = [19 x i8] c"Port_itoa (Port.c)\00"
@.str.3 = [28 x i8] c"Unsupported base! Fix this!\00"
define void @Port_itoa(i32 %0, i8* nocapture writeonly %1, i32 %2) {
switch i32 %2, label %8 [
i32 10, label %4
i32 16, label %6
]
4: ; preds = %3
%5 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %10
6: ; preds = %3
%7 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %10
8: ; preds = %3
%9 = tail call i32 @Port_Puts(i32 0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %10
10: ; preds = %6, %8, %4
ret void
}