#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*/ my_putchar(char);
int /*<<< orphan*/ my_puts(char *);
int my_put_nbr_base(int n, int base, int capitalized) {
  if (n < 0) {
    my_putchar('-');
    if (n != -2147483648) {
      my_put_nbr_base(-n, base, capitalized);
    } else {
      my_puts("2147483648");
    }
  } else if (n >= base) {
    my_put_nbr_base(n / base, base, capitalized);
    my_put_nbr_base(n % base, base, capitalized);
  } else if (n <= 9) {
    my_putchar(n + '0');
  } else {
    my_putchar((capitalized == 1 ? 'A' : 'a') + n - 10);
  }
  return (0);
}


x86 assembly (clang, -O0):
<my_put_nbr_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    118b <my_put_nbr_base+0x5b>
mov    $0x2d,%edi
call   1050 <my_putchar@plt>
movslq -0x4(%rbp),%rax
cmp    $0xffffffff80000000,%rax
je     117a <my_put_nbr_base+0x4a>
xor    %edi,%edi
sub    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <my_put_nbr_base@plt>
jmp    1186 <my_put_nbr_base+0x56>
lea    0xe7f(%rip),%rdi
call   1030 <my_puts@plt>
jmp    120c <my_put_nbr_base+0xdc>
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     11c4 <my_put_nbr_base+0x94>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <my_put_nbr_base@plt>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %edx,%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <my_put_nbr_base@plt>
jmp    1207 <my_put_nbr_base+0xd7>
cmpl   $0x9,-0x4(%rbp)
jg     11e1 <my_put_nbr_base+0xb1>
mov    -0x4(%rbp),%eax
add    $0x30,%eax
movsbl %al,%edi
call   1050 <my_putchar@plt>
jmp    1202 <my_put_nbr_base+0xd2>
mov    -0xc(%rbp),%edx
mov    $0x61,%eax
mov    $0x41,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
add    -0x4(%rbp),%eax
sub    $0xa,%eax
movsbl %al,%edi
call   1050 <my_putchar@plt>
jmp    1207 <my_put_nbr_base+0xd7>
jmp    120c <my_put_nbr_base+0xdc>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_put_nbr_base>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
nopl   0x0(%rax,%rax,1)
test   %ebx,%ebx
js     1160 <my_put_nbr_base+0x30>
cmp    %ebp,%ebx
jl     1176 <my_put_nbr_base+0x46>
mov    %ebx,%eax
cltd
idiv   %ebp
mov    %edx,%ebx
mov    %eax,%edi
mov    %ebp,%esi
mov    %r14d,%edx
call   1040 <my_put_nbr_base@plt>
jmp    1140 <my_put_nbr_base+0x10>
nopl   (%rax)
mov    $0x2d,%edi
call   1050 <my_putchar@plt>
cmp    $0x80000000,%ebx
je     1183 <my_put_nbr_base+0x53>
neg    %ebx
jmp    1140 <my_put_nbr_base+0x10>
cmp    $0x9,%ebx
ja     1191 <my_put_nbr_base+0x61>
add    $0x30,%bl
movsbl %bl,%edi
jmp    11a4 <my_put_nbr_base+0x74>
lea    0xe76(%rip),%rdi
call   1030 <my_puts@plt>
jmp    11a9 <my_put_nbr_base+0x79>
xor    %eax,%eax
cmp    $0x1,%r14d
setne  %al
shl    $0x5,%eax
add    %ebx,%eax
add    $0x37,%al
movsbl %al,%edi
call   1050 <my_putchar@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"2147483648\00"
define i32 @my_put_nbr_base(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %3
%10 = call i32 @my_putchar(i8 signext 45)
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = icmp ne i64 %12, -2147483648
br i1 %13, label %14, label %20
14: ; preds = %9
%15 = load i32, i32* %4
%16 = sub nsw i32 0, %15
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = call i32 @my_put_nbr_base(i32 %16, i32 %17, i32 %18)
br label %22
20: ; preds = %9
%21 = call i32 @my_puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %14
br label %60
23: ; preds = %3
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = icmp sge i32 %24, %25
br i1 %26, label %27, label %40
27: ; preds = %23
%28 = load i32, i32* %4
%29 = load i32, i32* %5
%30 = sdiv i32 %28, %29
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = call i32 @my_put_nbr_base(i32 %30, i32 %31, i32 %32)
%34 = load i32, i32* %4
%35 = load i32, i32* %5
%36 = srem i32 %34, %35
%37 = load i32, i32* %5
%38 = load i32, i32* %6
%39 = call i32 @my_put_nbr_base(i32 %36, i32 %37, i32 %38)
br label %59
40: ; preds = %23
%41 = load i32, i32* %4
%42 = icmp sle i32 %41, 9
br i1 %42, label %43, label %48
43: ; preds = %40
%44 = load i32, i32* %4
%45 = add nsw i32 %44, 48
%46 = trunc i32 %45 to i8
%47 = call i32 @my_putchar(i8 signext %46)
br label %58
48: ; preds = %40
%49 = load i32, i32* %6
%50 = icmp eq i32 %49, 1
%51 = zext i1 %50 to i64
%52 = select i1 %50, i32 65, i32 97
%53 = load i32, i32* %4
%54 = add nsw i32 %52, %53
%55 = sub nsw i32 %54, 10
%56 = trunc i32 %55 to i8
%57 = call i32 @my_putchar(i8 signext %56)
br label %58
58: ; preds = %48, %43
br label %59
59: ; preds = %58, %27
br label %60
60: ; preds = %59, %22
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"2147483648\00"
define i32 @my_put_nbr_base(i32 %0, i32 %1, i32 %2) {
br label %4
4: ; preds = %12, %3
%5 = phi i32 [ %0, %3 ], [ %13, %12 ]
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %4
%8 = tail call i32 @my_putchar(i8 signext 45)
%9 = icmp eq i32 %5, -2147483648
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = sub nsw i32 0, %5
br label %12
12: ; preds = %10, %18
%13 = phi i32 [ %11, %10 ], [ %21, %18 ]
br label %4
14: ; preds = %7
%15 = tail call i32 @my_puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %35
16: ; preds = %4
%17 = icmp slt i32 %5, %1
br i1 %17, label %22, label %18
18: ; preds = %16
%19 = sdiv i32 %5, %1
%20 = tail call i32 @my_put_nbr_base(i32 %19, i32 %1, i32 %2)
%21 = srem i32 %5, %1
br label %12
22: ; preds = %16
%23 = icmp ult i32 %5, 10
br i1 %23, label %24, label %28
24: ; preds = %22
%25 = trunc i32 %5 to i8
%26 = add nuw nsw i8 %25, 48
%27 = tail call i32 @my_putchar(i8 signext %26)
br label %35
28: ; preds = %22
%29 = icmp eq i32 %2, 1
%30 = select i1 %29, i32 65, i32 97
%31 = add nuw nsw i32 %5, %30
%32 = trunc i32 %31 to i8
%33 = add i8 %32, -10
%34 = tail call i32 @my_putchar(i8 signext %33)
br label %35
35: ; preds = %28, %24, %14
ret i32 0
}