#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*/ print_char(char, char);
void print_int(unsigned int num, char attr) {
  char digits[10];
  int i = 0;
  if (!num) {
    digits[i++] = 0;
  } else {
    while (num) {
      digits[i++] = num % 10;
      num /= 10;
    }
  }
  while (--i >= 0)
    print_char("0123456789"[digits[i]], attr);
}


x86 assembly (clang, -O0):
<print_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1149 <print_int+0x39>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
cltq
movb   $0x0,-0xf(%rbp,%rax,1)
jmp    1190 <print_int+0x80>
jmp    114e <print_int+0x3e>
cmpl   $0x0,-0x4(%rbp)
je     118b <print_int+0x7b>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %dl,%cl
mov    -0x14(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
cltq
mov    %cl,-0xf(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x4(%rbp)
jmp    114e <print_int+0x3e>
jmp    1190 <print_int+0x80>
jmp    1195 <print_int+0x85>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jl     11cc <print_int+0xbc>
movslq -0x14(%rbp),%rax
movsbq -0xf(%rbp,%rax,1),%rcx
lea    0xe48(%rip),%rax
mov    (%rax,%rcx,1),%al
movsbl %al,%edi
movsbl -0x5(%rbp),%esi
call   1030 <print_char@plt>
jmp    1195 <print_int+0x85>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_int>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
je     1158 <print_int+0x48>
xor    %eax,%eax
mov    $0xcccccccd,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %edi,%edx
imul   %rcx,%rdx
shr    $0x23,%rdx
lea    (%rdx,%rdx,1),%ebp
lea    0x0(%rbp,%rbp,4),%ebp
mov    %edi,%ebx
sub    %ebp,%ebx
mov    %bl,0xe(%rsp,%rax,1)
add    $0x1,%rax
cmp    $0x9,%edi
mov    %edx,%edi
ja     1130 <print_int+0x20>
mov    %eax,%eax
jmp    1162 <print_int+0x52>
movb   $0x0,0xe(%rsp)
mov    $0x1,%eax
lea    0x1(%rax),%ebp
add    $0xffffffff,%eax
lea    (%rsp,%rax,1),%rbx
add    $0xe,%rbx
lea    0xe89(%rip),%r15
movsbl %sil,%r14d
nopl   0x0(%rax,%rax,1)
movsbq (%rbx),%rax
movsbl (%rax,%r15,1),%edi
mov    %r14d,%esi
call   1030 <print_char@plt>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%ebp
jg     1180 <print_int+0x70>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"0123456789\00"
define void @print_int(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca [10 x i8]
%6 = alloca i32
store i32 %0, i32* %3
store i8 %1, i8* %4
store i32 0, i32* %6
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = load i32, i32* %6
%11 = add nsw i32 %10, 1
store i32 %11, i32* %6
%12 = sext i32 %10 to i64
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 %12
store i8 0, i8* %13
br label %29
14: ; preds = %2
br label %15
15: ; preds = %18, %14
%16 = load i32, i32* %3
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %15
%19 = load i32, i32* %3
%20 = urem i32 %19, 10
%21 = trunc i32 %20 to i8
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 %24
store i8 %21, i8* %25
%26 = load i32, i32* %3
%27 = udiv i32 %26, 10
store i32 %27, i32* %3
br label %15
28: ; preds = %15
br label %29
29: ; preds = %28, %9
br label %30
30: ; preds = %34, %29
%31 = load i32, i32* %6
%32 = add nsw i32 %31, -1
store i32 %32, i32* %6
%33 = icmp sge i32 %32, 0
br i1 %33, label %34, label %44
34: ; preds = %30
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i64
%40 = getelementptr inbounds [11 x i8], [11 x i8]* @.str, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = load i8, i8* %4
%43 = call i32 @print_char(i8 signext %41, i8 signext %42)
br label %30
44: ; preds = %30
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"0123456789\00"
define void @print_int(i32 %0, i8 signext %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 0
br i1 %5, label %6, label %7
6: ; preds = %2
store i8 0, i8* %4
br label %18
7: ; preds = %2, %7
%8 = phi i64 [ %12, %7 ], [ 0, %2 ]
%9 = phi i32 [ %14, %7 ], [ %0, %2 ]
%10 = urem i32 %9, 10
%11 = trunc i32 %10 to i8
%12 = add nuw i64 %8, 1
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %8
store i8 %11, i8* %13
%14 = udiv i32 %9, 10
%15 = icmp ult i32 %9, 10
br i1 %15, label %16, label %7
16: ; preds = %7
%17 = and i64 %12, 4294967295
br label %18
18: ; preds = %6, %16
%19 = phi i64 [ %17, %16 ], [ 1, %6 ]
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ %22, %20 ], [ %19, %18 ]
%22 = add nsw i64 %21, -1
%23 = and i64 %22, 4294967295
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i64
%27 = getelementptr inbounds [11 x i8], [11 x i8]* @.str, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = tail call i32 @print_char(i8 signext %28, i8 signext %1)
%30 = trunc i64 %21 to i32
%31 = icmp sgt i32 %30, 1
br i1 %31, label %20, label %32
32: ; preds = %20
ret void
}