#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 scalar_t__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ terminal_putchar(char);
void terminal_writenum(uint32_t n) {
  if (n == 0) {
    terminal_putchar('0');
    return;
  } else {
    uint32_t acc = n;
    char num[32];
    int i = 0;
    while (acc > 0) {
      num[i] = '0' + acc % 10;
      acc /= 10;
      i++;
    }
    while (i > 0) {
      terminal_putchar(num[--i]);
    }
  }
}


x86 assembly (clang, -O0):
<terminal_writenum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1136 <terminal_writenum+0x26>
mov    $0x30,%edi
call   1030 <terminal_putchar@plt>
jmp    11ba <terminal_writenum+0xaa>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    118c <terminal_writenum+0x7c>
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
add    $0x30,%rdx
mov    %dl,%cl
movslq -0x34(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1145 <terminal_writenum+0x35>
jmp    1191 <terminal_writenum+0x81>
cmpl   $0x0,-0x34(%rbp)
jle    11b5 <terminal_writenum+0xa5>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
cltq
movsbl -0x30(%rbp,%rax,1),%edi
call   1030 <terminal_putchar@plt>
jmp    1191 <terminal_writenum+0x81>
jmp    11ba <terminal_writenum+0xaa>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<terminal_writenum>:
test   %rdi,%rdi
je     118c <terminal_writenum+0x7c>
push   %rbx
lea    -0x20(%rsp),%rsp
jle    1186 <terminal_writenum+0x76>
xor    %ecx,%ecx
movabs $0xcccccccccccccccd,%rsi
cc cc cc
nopl   0x0(%rax)
mov    %rdi,%rax
mul    %rsi
shr    $0x3,%rdx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %edi,%ebx
sub    %eax,%ebx
or     $0x30,%bl
mov    %bl,(%rsp,%rcx,1)
add    $0x1,%rcx
cmp    $0xa,%rdi
mov    %rdx,%rdi
jae    1130 <terminal_writenum+0x20>
test   %ecx,%ecx
jle    1186 <terminal_writenum+0x76>
mov    %ecx,%ebx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rbx),%eax
movsbl (%rsp,%rax,1),%edi
call   1030 <terminal_putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1170 <terminal_writenum+0x60>
add    $0x20,%rsp
pop    %rbx
ret
mov    $0x30,%edi
jmp    1030 <terminal_putchar@plt>

LLVM IR (-O0):
define void @terminal_writenum(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca [32 x i8]
%5 = alloca i32
store i64 %0, i64* %2
%6 = load i64, i64* %2
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @terminal_putchar(i8 signext 48)
br label %39
10: ; preds = %1
%11 = load i64, i64* %2
store i64 %11, i64* %3
store i32 0, i32* %5
br label %12
12: ; preds = %15, %10
%13 = load i64, i64* %3
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %27
15: ; preds = %12
%16 = load i64, i64* %3
%17 = srem i64 %16, 10
%18 = add nsw i64 48, %17
%19 = trunc i64 %18 to i8
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %21
store i8 %19, i8* %22
%23 = load i64, i64* %3
%24 = sdiv i64 %23, 10
store i64 %24, i64* %3
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %12
27: ; preds = %12
br label %28
28: ; preds = %31, %27
%29 = load i32, i32* %5
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = load i32, i32* %5
%33 = add nsw i32 %32, -1
store i32 %33, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = call i32 @terminal_putchar(i8 signext %36)
br label %28
38: ; preds = %28
br label %39
39: ; preds = %8, %38
ret void
}

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