#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 */
struct print_context {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int print_str(struct print_context *, char *);
int __print_number(struct print_context *ctx, unsigned int neg, unsigned int n,
                   unsigned int base, const char *table) {
  char buf[12];
  char *ptr;
  buf[sizeof(buf) - 1] = '\0';
  ptr = &buf[sizeof(buf) - 1];
  if (n == 0) {
    *(--ptr) = '0';
  } else {
    do {
      *(--ptr) = table[n % base];
      n /= base;
    } while (n != 0);
  }
  if (neg)
    *(--ptr) = '-';
  return print_str(ctx, ptr);
}


x86 assembly (clang, -O0):
<__print_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
movb   $0x0,-0x21(%rbp)
lea    -0x2c(%rbp),%rax
add    $0xb,%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    115b <__print_number+0x4b>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x30,-0x1(%rax)
jmp    11a7 <__print_number+0x97>
jmp    1160 <__print_number+0x50>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%eax
xor    %edx,%edx
divl   -0x14(%rbp)
mov    -0x40(%rbp),%rax
mov    %edx,%ecx
mov    (%rax,%rcx,1),%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%eax
xor    %edx,%edx
div    %ecx
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1160 <__print_number+0x50>
jmp    11a7 <__print_number+0x97>
cmpl   $0x0,-0xc(%rbp)
je     11c4 <__print_number+0xb4>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x2d,-0x1(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <print_str@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__print_number>:
sub    $0x18,%rsp
mov    %esi,%r9d
movb   $0x0,0x17(%rsp)
test   %edx,%edx
je     1162 <__print_number+0x52>
mov    %edx,%r10d
lea    0x17(%rsp),%rsi
nopl   0x0(%rax,%rax,1)
mov    %r10d,%eax
xor    %edx,%edx
div    %ecx
movzbl (%r8,%rdx,1),%edx
mov    %dl,-0x1(%rsi)
add    $0xffffffffffffffff,%rsi
cmp    %ecx,%r10d
mov    %eax,%r10d
jae    1130 <__print_number+0x20>
test   %r9d,%r9d
je     1158 <__print_number+0x48>
movb   $0x2d,-0x1(%rsi)
add    $0xffffffffffffffff,%rsi
call   1030 <print_str@plt>
add    $0x18,%rsp
ret
lea    0x16(%rsp),%rsi
movb   $0x30,0x16(%rsp)
test   %r9d,%r9d
jne    1150 <__print_number+0x40>
jmp    1158 <__print_number+0x48>

LLVM IR (-O0):
%struct.print_context = type { i32 }
define i32 @__print_number(%struct.print_context* %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca %struct.print_context*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [12 x i8]
%12 = alloca i8*
store %struct.print_context* %0, %struct.print_context** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%13 = getelementptr inbounds [12 x i8], [12 x i8]* %11, i64 0, i64 11
store i8 0, i8* %13
%14 = getelementptr inbounds [12 x i8], [12 x i8]* %11, i64 0, i64 11
store i8* %14, i8** %12
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %5
%18 = load i8*, i8** %12
%19 = getelementptr inbounds i8, i8* %18, i32 -1
store i8* %19, i8** %12
store i8 48, i8* %19
br label %38
20: ; preds = %5
br label %21
21: ; preds = %34, %20
%22 = load i8*, i8** %10
%23 = load i32, i32* %8
%24 = load i32, i32* %9
%25 = urem i32 %23, %24
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %22, i64 %26
%28 = load i8, i8* %27
%29 = load i8*, i8** %12
%30 = getelementptr inbounds i8, i8* %29, i32 -1
store i8* %30, i8** %12
store i8 %28, i8* %30
%31 = load i32, i32* %9
%32 = load i32, i32* %8
%33 = udiv i32 %32, %31
store i32 %33, i32* %8
br label %34
34: ; preds = %21
%35 = load i32, i32* %8
%36 = icmp ne i32 %35, 0
br i1 %36, label %21, label %37
37: ; preds = %34
br label %38
38: ; preds = %37, %17
%39 = load i32, i32* %7
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i8*, i8** %12
%43 = getelementptr inbounds i8, i8* %42, i32 -1
store i8* %43, i8** %12
store i8 45, i8* %43
br label %44
44: ; preds = %41, %38
%45 = load %struct.print_context*, %struct.print_context** %6
%46 = load i8*, i8** %12
%47 = call i32 @print_str(%struct.print_context* %45, i8* %46)
ret i32 %47
}

LLVM IR (-O2):
%struct.print_context = type { i32 }
define i32 @__print_number(%struct.print_context* %0, i32 %1, i32 %2, i32 %3, i8* nocapture %4) {
%6 = alloca [12 x i8]
%7 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%8 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 11
store i8 0, i8* %8
%9 = icmp eq i32 %2, 0
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 10
store i8 48, i8* %11
br label %22
12: ; preds = %5, %12
%13 = phi i32 [ %20, %12 ], [ %2, %5 ]
%14 = phi i8* [ %19, %12 ], [ %8, %5 ]
%15 = urem i32 %13, %3
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %4, i64 %16
%18 = load i8, i8* %17
%19 = getelementptr inbounds i8, i8* %14, i64 -1
store i8 %18, i8* %19
%20 = udiv i32 %13, %3
%21 = icmp ult i32 %13, %3
br i1 %21, label %22, label %12
22: ; preds = %12, %10
%23 = phi i8* [ %11, %10 ], [ %19, %12 ]
%24 = icmp eq i32 %1, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = getelementptr inbounds i8, i8* %23, i64 -1
store i8 45, i8* %26
br label %27
27: ; preds = %25, %22
%28 = phi i8* [ %26, %25 ], [ %23, %22 ]
%29 = call i32 @print_str(%struct.print_context* %0, i8* %28)
ret i32 %29
}