#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 */
typedef int /*<<< orphan*/ tab;

/* Variables and functions */
int /*<<< orphan*/ print(char *, int);
void printbase(unsigned int i, int base, unsigned char flags) {
  static char tab[32] = "0123456789abcdef0123456789ABCDEF";
  if (i / base != 0)
    printbase(i / base, base, flags);
  if (flags & 0x01) {
    print(&tab[(i % base) + 16], sizeof(tab[i % base]));
  } else {
    print(&tab[i % base], sizeof(tab[i % base]));
  }
}


x86 assembly (clang, -O0):
<printbase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
cmp    $0x0,%eax
je     115a <printbase+0x3a>
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %eax,%edi
mov    -0x8(%rbp),%esi
movzbl -0x9(%rbp),%edx
call   1030 <printbase@plt>
movzbl -0x9(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1190 <printbase+0x70>
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
add    $0x10,%edx
mov    %edx,%eax
lea    0x2ec2(%rip),%rdi
add    %rax,%rdi
mov    $0x1,%esi
call   1040 <print@plt>
jmp    11ae <printbase+0x8e>
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %edx,%eax
lea    0x2e9f(%rip),%rdi
add    %rax,%rdi
mov    $0x1,%esi
call   1040 <print@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printbase>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
cmp    %edi,%esi
ja     1142 <printbase+0x22>
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
movzbl %r14b,%edx
mov    %eax,%edi
mov    %ebp,%esi
call   1030 <printbase@plt>
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
lea    0x10(%rdx),%eax
test   $0x1,%r14b
cmove  %edx,%eax
lea    0x2ee7(%rip),%rdi
add    %rax,%rdi
mov    $0x1,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <print@plt>

LLVM IR (-O0):
@printbase.tab = internal global [32 x i8] c"0123456789abcdef0123456789ABCDEF"
define void @printbase(i32 %0, i32 %1, i8 zeroext %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* %4
%8 = load i32, i32* %5
%9 = udiv i32 %7, %8
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i32, i32* %4
%13 = load i32, i32* %5
%14 = udiv i32 %12, %13
%15 = load i32, i32* %5
%16 = load i8, i8* %6
br label %17
17: ; preds = %11, %3
%18 = load i8, i8* %6
%19 = zext i8 %18 to i32
%20 = and i32 %19, 1
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %17
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = urem i32 %23, %24
%26 = add i32 %25, 16
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds [32 x i8], [32 x i8]* @printbase.tab, i64 0, i64 %27
%29 = call i32 @print(i8* %28, i32 1)
br label %37
30: ; preds = %17
%31 = load i32, i32* %4
%32 = load i32, i32* %5
%33 = urem i32 %31, %32
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds [32 x i8], [32 x i8]* @printbase.tab, i64 0, i64 %34
%36 = call i32 @print(i8* %35, i32 1)
br label %37
37: ; preds = %30, %22
ret void
}

LLVM IR (-O2):
@printbase.tab = internal global [32 x i8] c"0123456789abcdef0123456789ABCDEF"
define void @printbase(i32 %0, i32 %1, i8 zeroext %2) {
%4 = icmp ugt i32 %1, %0
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = udiv i32 %0, %1
tail call void @printbase(i32 %6, i32 %1, i8 zeroext %2)
br label %7
7: ; preds = %5, %3
%8 = and i8 %2, 1
%9 = icmp eq i8 %8, 0
%10 = urem i32 %0, %1
%11 = add i32 %10, 16
%12 = select i1 %9, i32 %10, i32 %11
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds [32 x i8], [32 x i8]* @printbase.tab, i64 0, i64 %13
%15 = tail call i32 @print(i8* %14, i32 1)
ret void
}