#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 int32_t;
typedef int int16_t;

/* Variables and functions */
int /*<<< orphan*/ gwrite(int, int, int, int);
void writenum(int32_t n, int16_t x, int16_t y, int16_t w, int16_t c) {
  int16_t d, xp = (w - 1) * 12 + x;
  while (w > 0) {
    d = (int16_t)(n % 10);
    if (w > 1 || d > 0)
      gwrite(xp, y, d + '0', c);
    n /= 10;
    w--;
    xp -= 12;
  }
}


x86 assembly (clang, -O0):
<writenum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
imul   $0xc,%eax,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    119c <writenum+0x8c>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
cmpl   $0x1,-0x10(%rbp)
jg     1163 <writenum+0x53>
cmpl   $0x0,-0x18(%rbp)
jle    1177 <writenum+0x67>
mov    -0x1c(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
add    $0x30,%edx
mov    -0x14(%rbp),%ecx
call   1030 <gwrite@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0xc,%eax
mov    %eax,-0x1c(%rbp)
jmp    1137 <writenum+0x27>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writenum>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %ecx,%ecx
jle    1186 <writenum+0x76>
mov    %r8d,%r14d
mov    %ecx,%ebx
mov    %edx,%r15d
mov    %edi,%ebp
lea    (%rbx,%rbx,2),%eax
lea    (%rsi,%rax,4),%r12d
add    $0xfffffff4,%r12d
add    $0x1,%ebx
jmp    115d <writenum+0x4d>
cs nopw 0x0(%rax,%rax,1)
add    $0x30,%edx
mov    %r12d,%edi
mov    %r15d,%esi
mov    %r14d,%ecx
call   1030 <gwrite@plt>
add    $0xfffffff4,%r12d
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
jbe    1186 <writenum+0x76>
movslq %ebp,%rdx
imul   $0x66666667,%rdx,%rbp
mov    %rbp,%rax
shr    $0x3f,%rax
sar    $0x22,%rbp
add    %eax,%ebp
lea    0x0(%rbp,%rbp,1),%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
cmp    $0x2,%ebx
jne    1140 <writenum+0x30>
test   %edx,%edx
jg     1140 <writenum+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @writenum(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%13 = load i32, i32* %9
%14 = sub nsw i32 %13, 1
%15 = mul nsw i32 %14, 12
%16 = load i32, i32* %7
%17 = add nsw i32 %15, %16
store i32 %17, i32* %12
br label %18
18: ; preds = %36, %5
%19 = load i32, i32* %9
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %43
21: ; preds = %18
%22 = load i32, i32* %6
%23 = srem i32 %22, 10
store i32 %23, i32* %11
%24 = load i32, i32* %9
%25 = icmp sgt i32 %24, 1
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = load i32, i32* %11
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %26, %21
%30 = load i32, i32* %12
%31 = load i32, i32* %8
%32 = load i32, i32* %11
%33 = add nsw i32 %32, 48
%34 = load i32, i32* %10
%35 = call i32 @gwrite(i32 %30, i32 %31, i32 %33, i32 %34)
br label %36
36: ; preds = %29, %26
%37 = load i32, i32* %6
%38 = sdiv i32 %37, 10
store i32 %38, i32* %6
%39 = load i32, i32* %9
%40 = add nsw i32 %39, -1
store i32 %40, i32* %9
%41 = load i32, i32* %12
%42 = sub nsw i32 %41, 12
store i32 %42, i32* %12
br label %18
43: ; preds = %18
ret void
}

LLVM IR (-O2):
define void @writenum(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %26
7: ; preds = %5
%8 = add i32 %1, -12
%9 = mul i32 %3, 12
%10 = add i32 %8, %9
br label %11
11: ; preds = %7, %20
%12 = phi i32 [ %24, %20 ], [ %10, %7 ]
%13 = phi i32 [ %16, %20 ], [ %0, %7 ]
%14 = phi i32 [ %23, %20 ], [ %3, %7 ]
%15 = srem i32 %13, 10
%16 = sdiv i32 %13, 10
%17 = icmp ne i32 %14, 1
%18 = icmp sgt i32 %15, 0
%19 = select i1 %17, i1 true, i1 %18
br i1 %19, label %20, label %26
20: ; preds = %11
%21 = add nsw i32 %15, 48
%22 = tail call i32 @gwrite(i32 %12, i32 %2, i32 %21, i32 %4)
%23 = add nsw i32 %14, -1
%24 = add nsw i32 %12, -12
%25 = icmp ugt i32 %14, 1
br i1 %25, label %11, label %26
26: ; preds = %11, %20, %5
ret void
}