#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*/ num2str(int, int, char *);
int /*<<< orphan*/ printf(char *, int, char *);
int main() {
  char buf[16];
  int tests[] = {0, 0xBADBEEF, 0xDEAD, 0xFEDE, 0xAAAA, 0x1234, 0xFFFFFFFF};
  int i;
  for (i = 0; i < 7; i++) {
    num2str(tests[i], 16, buf);
    printf("%x: %s\n", tests[i], buf);
  }
  for (i = 0; i < 30; i++) {
    num2str(i, 10, buf);
    printf("%d: %s\n", i, buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xec4(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xec2(%rip),%eax
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x7,-0x44(%rbp)
jge    11a6 <main+0x86>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%edi
lea    -0x20(%rbp),%rdx
mov    $0x10,%esi
call   1040 <num2str@plt>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    -0x20(%rbp),%rdx
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1160 <main+0x40>
movl   $0x0,-0x44(%rbp)
cmpl   $0x1e,-0x44(%rbp)
jge    11e9 <main+0xc9>
mov    -0x44(%rbp),%edi
lea    -0x20(%rbp),%rdx
mov    $0xa,%esi
call   1040 <num2str@plt>
mov    -0x44(%rbp),%esi
lea    -0x20(%rbp),%rdx
lea    0xe4e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11ad <main+0x8d>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
mov    %rsp,%r14
xor    %edi,%edi
mov    $0x10,%esi
mov    %r14,%rdx
call   1040 <num2str@plt>
lea    0xebc(%rip),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    $0xbadbeef,%edi
mov    $0x10,%esi
mov    %r14,%rdx
call   1040 <num2str@plt>
mov    %r15,%rdi
mov    $0xbadbeef,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    $0xdead,%edi
mov    $0x10,%esi
mov    %r14,%rdx
call   1040 <num2str@plt>
mov    %r15,%rdi
mov    $0xdead,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    $0xfede,%edi
mov    $0x10,%esi
mov    %r14,%rdx
call   1040 <num2str@plt>
mov    %r15,%rdi
mov    $0xfede,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    $0xaaaa,%edi
mov    $0x10,%esi
mov    %r14,%rdx
call   1040 <num2str@plt>
mov    %r15,%rdi
mov    $0xaaaa,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    $0x1234,%edi
mov    $0x10,%esi
mov    %r14,%rdx
call   1040 <num2str@plt>
mov    %r15,%rdi
mov    $0x1234,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    $0xffffffff,%edi
mov    $0x10,%esi
mov    %r14,%rdx
call   1040 <num2str@plt>
mov    %r15,%rdi
mov    $0xffffffff,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
lea    0xde4(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
mov    $0xa,%esi
mov    %r14,%rdx
call   1040 <num2str@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    $0x1e,%ebx
jne    1230 <main+0x110>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.tests = [7 x i32] [i32 0, i32 195935983, i32 57005, i32 65246, i32 43690, i32 4660, i32 -1]
@.str = [8 x i8] c"%x: %s\0A\00"
@.str.1 = [8 x i8] c"%d: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca [7 x i32]
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [7 x i32]* %3 to i8*
store i32 0, i32* %4
br label %6
6: ; preds = %22, %0
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 7
br i1 %8, label %9, label %25
9: ; preds = %6
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [7 x i32], [7 x i32]* %3, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%15 = call i32 @num2str(i32 %13, i32 16, i8* %14)
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [7 x i32], [7 x i32]* %3, i64 0, i64 %17
%19 = load i32, i32* %18
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%21 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %19, i8* %20)
br label %22
22: ; preds = %9
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %6
25: ; preds = %6
store i32 0, i32* %4
br label %26
26: ; preds = %36, %25
%27 = load i32, i32* %4
%28 = icmp slt i32 %27, 30
br i1 %28, label %29, label %39
29: ; preds = %26
%30 = load i32, i32* %4
%31 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%32 = call i32 @num2str(i32 %30, i32 10, i8* %31)
%33 = load i32, i32* %4
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%35 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %33, i8* %34)
br label %36
36: ; preds = %29
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %26
39: ; preds = %26
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"%x: %s\0A\00"
@.str.1 = [8 x i8] c"%d: %s\0A\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%3 = call i32 @num2str(i32 0, i32 16, i8* %2)
%4 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 0, i8* %2)
%5 = call i32 @num2str(i32 195935983, i32 16, i8* %2)
%6 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 195935983, i8* %2)
%7 = call i32 @num2str(i32 57005, i32 16, i8* %2)
%8 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 57005, i8* %2)
%9 = call i32 @num2str(i32 65246, i32 16, i8* %2)
%10 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 65246, i8* %2)
%11 = call i32 @num2str(i32 43690, i32 16, i8* %2)
%12 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 43690, i8* %2)
%13 = call i32 @num2str(i32 4660, i32 16, i8* %2)
%14 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 4660, i8* %2)
%15 = call i32 @num2str(i32 -1, i32 16, i8* %2)
%16 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 -1, i8* %2)
br label %17
17: ; preds = %0, %17
%18 = phi i32 [ %21, %17 ], [ 0, %0 ]
%19 = call i32 @num2str(i32 %18, i32 10, i8* %2)
%20 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %18, i8* %2)
%21 = add nuw nsw i32 %18, 1
%22 = icmp eq i32 %21, 30
br i1 %22, label %23, label %17
23: ; preds = %17
ret i32 0
}