#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);
void num_to_string(int num_conv, int cvt_type, char *str_tmp) {
  switch (cvt_type) {
  case 2:
    sprintf(str_tmp, "%o", num_conv);
    break;
  case 1:
    sprintf(str_tmp, "%x", num_conv);
    break;
  case 0:
  default:
    sprintf(str_tmp, "%d", num_conv);
    break;
  }
}


x86 assembly (clang, -O0):
<num_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     1187 <num_to_string+0x77>
jmp    1135 <num_to_string+0x25>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
je     116f <num_to_string+0x5f>
jmp    1146 <num_to_string+0x36>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
jne    118c <num_to_string+0x7c>
jmp    1157 <num_to_string+0x47>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe9b(%rip),%rsi
call   1030 <sprintf@plt>
jmp    119f <num_to_string+0x8f>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe86(%rip),%rsi
call   1030 <sprintf@plt>
jmp    119f <num_to_string+0x8f>
jmp    118c <num_to_string+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe6c(%rip),%rsi
call   1030 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_to_string>:
mov    %edi,%eax
cmp    $0x1,%esi
lea    0xee7(%rip),%rcx
lea    0xee3(%rip),%rdi
cmove  %rcx,%rdi
cmp    $0x2,%esi
lea    0xecf(%rip),%rsi
cmovne %rdi,%rsi
mov    %rdx,%rdi
mov    %eax,%edx
jmp    1030 <sprintf@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"%o\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [3 x i8] c"%d\00"
define void @num_to_string(i32 %0, i32 %1, i8* nocapture writeonly %2) {
%4 = icmp eq i32 %1, 1
%5 = select i1 %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%6 = icmp eq i32 %1, 2
%7 = select i1 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) %7, i32 %0)
ret void
}