#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*/ printf(char *, ...);
long strtol(char *, char **, int);
int main(int argc, char *argv[]) {
  if (argc > 1) {
    char *ptr;
    long ret;
    ret = strtol(argv[1], &ptr, 10);
    const char baseDigits[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
                                 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
    int convertedNumber[64];
    long int numberToConvert = ret;
    int nextDigit, base = 16, index = 0;
    do {
      convertedNumber[index] = numberToConvert % base;
      ++index;
      numberToConvert = numberToConvert / base;
    } while (numberToConvert != 0);
    printf("Converted number = ");
    for (--index; index >= 0; --index) {
      nextDigit = convertedNumber[index];
      printf("%c", baseDigits[nextDigit]);
    }
    printf("\n");
    return 0;
  } else {
    printf("\nIllegal usage, please supply an integer\n\n");
    printf("usage: tobase16 <integer>\n\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1272 <main+0x152>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    0xe9c(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe99(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x138(%rbp)
movl   $0x10,-0x140(%rbp)
movl   $0x0,-0x144(%rbp)
mov    -0x138(%rbp),%rax
movslq -0x140(%rbp),%rcx
cqto
idiv   %rcx
mov    %edx,%ecx
movslq -0x144(%rbp),%rax
mov    %ecx,-0x130(%rbp,%rax,4)
mov    -0x144(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x144(%rbp)
mov    -0x138(%rbp),%rax
movslq -0x140(%rbp),%rcx
cqto
idiv   %rcx
mov    %rax,-0x138(%rbp)
cmpq   $0x0,-0x138(%rbp)
jne    1192 <main+0x72>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x144(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x144(%rbp)
cmpl   $0x0,-0x144(%rbp)
jl     1258 <main+0x138>
movslq -0x144(%rbp),%rax
mov    -0x130(%rbp,%rax,4),%eax
mov    %eax,-0x13c(%rbp)
movslq -0x13c(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%esi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x144(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x144(%rbp)
jmp    1209 <main+0xe9>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1295 <main+0x175>
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x118,%rsp
cmp    $0x2,%edi
jl     11e8 <main+0xa8>
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
xor    %r14d,%r14d
mov    %rax,%rcx
lea    0xf(%rax),%rdx
test   %rax,%rax
cmovs  %rdx,%rcx
sar    $0x4,%rcx
mov    %ecx,%esi
shl    $0x4,%esi
sub    %esi,%eax
mov    %eax,0x10(%rsp,%r14,4)
add    $0x1,%r14
mov    %rcx,%rax
cmp    $0x1e,%rdx
ja     1170 <main+0x30>
lea    0xe71(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffffffffffff,%r14
mov    %r14d,%eax
lea    (%rsp,%rax,4),%r15
add    $0x10,%r15
lea    0xe42(%rip),%r12
xchg   %ax,%ax
movslq (%r15,%rbx,4),%rax
movsbl (%rax,%r12,1),%edi
call   1030 <putchar@plt>
lea    -0x1(%rbx),%rax
add    %r14d,%ebx
test   %ebx,%ebx
mov    %rax,%rbx
jg     11c0 <main+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1200 <main+0xc0>
lea    0xe35(%rip),%rdi
call   1040 <puts@plt>
lea    0xe53(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.baseDigits = [16 x i8] c"0123456789ABCDEF"
@.str = [20 x i8] c"Converted number = \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [43 x i8] c"\0AIllegal usage, please supply an integer\0A\0A\00"
@.str.4 = [28 x i8] c"usage: tobase16 <integer>\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [16 x i8]
%9 = alloca [64 x i32]
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %64
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @strtol(i8* %19, i8** %6, i32 10)
store i64 %20, i64* %7
%21 = bitcast [16 x i8]* %8 to i8*
%22 = load i64, i64* %7
store i64 %22, i64* %10
store i32 16, i32* %12
store i32 0, i32* %13
br label %23
23: ; preds = %38, %16
%24 = load i64, i64* %10
%25 = load i32, i32* %12
%26 = sext i32 %25 to i64
%27 = srem i64 %24, %26
%28 = trunc i64 %27 to i32
%29 = load i32, i32* %13
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [64 x i32], [64 x i32]* %9, i64 0, i64 %30
store i32 %28, i32* %31
%32 = load i32, i32* %13
%33 = add nsw i32 %32, 1
store i32 %33, i32* %13
%34 = load i64, i64* %10
%35 = load i32, i32* %12
%36 = sext i32 %35 to i64
%37 = sdiv i64 %34, %36
store i64 %37, i64* %10
br label %38
38: ; preds = %23
%39 = load i64, i64* %10
%40 = icmp ne i64 %39, 0
br i1 %40, label %23, label %41
41: ; preds = %38
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%43 = load i32, i32* %13
%44 = add nsw i32 %43, -1
store i32 %44, i32* %13
br label %45
45: ; preds = %59, %41
%46 = load i32, i32* %13
%47 = icmp sge i32 %46, 0
br i1 %47, label %48, label %62
48: ; preds = %45
%49 = load i32, i32* %13
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [64 x i32], [64 x i32]* %9, i64 0, i64 %50
%52 = load i32, i32* %51
store i32 %52, i32* %11
%53 = load i32, i32* %11
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %48
%60 = load i32, i32* %13
%61 = add nsw i32 %60, -1
store i32 %61, i32* %13
br label %45
62: ; preds = %45
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %67
64: ; preds = %2
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %67
67: ; preds = %64, %62
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@__const.main.baseDigits = [16 x i8] c"0123456789ABCDEF"
@.str = [20 x i8] c"Converted number = \00"
@str = [42 x i8] c"\0AIllegal usage, please supply an integer\0A\00"
@str.5 = [27 x i8] c"usage: tobase16 <integer>\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca [64 x i32]
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %39
6: ; preds = %2
%7 = bitcast i8** %3 to i8*
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = call i64 @strtol(i8* %9, i8** %3, i32 10)
%11 = bitcast [64 x i32]* %4 to i8*
br label %12
12: ; preds = %12, %6
%13 = phi i64 [ %18, %12 ], [ 0, %6 ]
%14 = phi i64 [ %19, %12 ], [ %10, %6 ]
%15 = srem i64 %14, 16
%16 = trunc i64 %15 to i32
%17 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 %13
store i32 %16, i32* %17
%18 = add nuw i64 %13, 1
%19 = sdiv i64 %14, 16
%20 = add i64 %14, 15
%21 = icmp ult i64 %20, 31
br i1 %21, label %22, label %12
22: ; preds = %12
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%24 = and i64 %13, 4294967295
br label %25
25: ; preds = %22, %25
%26 = phi i64 [ %24, %22 ], [ %34, %25 ]
%27 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [16 x i8], [16 x i8]* @__const.main.baseDigits, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = tail call i32 @putchar(i32 %32)
%34 = add nsw i64 %26, -1
%35 = trunc i64 %26 to i32
%36 = icmp sgt i32 %35, 0
br i1 %36, label %25, label %37
37: ; preds = %25
%38 = tail call i32 @putchar(i32 10)
br label %42
39: ; preds = %2
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
br label %42
42: ; preds = %39, %37
ret i32 0
}