#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*/ draw_text(unsigned int *, int, int, int, int, unsigned long,
                             unsigned char *);
int draw_int(unsigned int *fnt_ptr, int font_w, int font_h, int x, int y,
             unsigned long color, unsigned long val) {
  unsigned long divisor = 10000000L;
  unsigned char nibble;
  unsigned char data_buf[15];
  int index = 0;
  val = val % 100000000L;
  while (divisor > 0) {
    nibble = val / divisor;
    data_buf[index++] = nibble + '0';
    val = val - (nibble * divisor);
    x++;
    divisor /= 10;
  }
  data_buf[index] = 0;
  draw_text(fnt_ptr, font_w, font_h, x, y, color, data_buf);
  return 0;
}


x86 assembly (clang, -O0):
<draw_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
movq   $0x989680,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    0x10(%rbp),%rax
mov    $0x5f5e100,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,0x10(%rbp)
cmpq   $0x0,-0x28(%rbp)
jbe    11ba <draw_int+0xaa>
mov    0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x28(%rbp)
mov    %al,-0x29(%rbp)
movzbl -0x29(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x3c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x3c(%rbp)
cltq
mov    %cl,-0x38(%rbp,%rax,1)
mov    0x10(%rbp),%rax
movzbl -0x29(%rbp),%ecx
imul   -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x28(%rbp)
jmp    1152 <draw_int+0x42>
movslq -0x3c(%rbp),%rax
movb   $0x0,-0x38(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x20(%rbp),%r9
lea    -0x38(%rbp),%rax
mov    %rax,(%rsp)
call   1030 <draw_text@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_int>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r10d
mov    0x30(%rsp),%r11
movabs $0xabcc77118461cefd,%rdx
77 cc ab
mov    %r11,%rax
mul    %rdx
shr    $0x1a,%rdx
imul   $0x5f5e100,%rdx,%rax
sub    %rax,%r11
imul   $0x6b5fca6b,%r11,%rax
shr    $0x36,%rax
imul   $0xffffffffff676980,%rax,%rbx
or     $0x30,%al
mov    %al,0x9(%rsp)
add    %r11,%rbx
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mov    %rbx,%rax
mul    %rdx
shr    $0x12,%rdx
lea    0x30(%rdx),%eax
mov    %al,0xa(%rsp)
movzbl %dl,%eax
imul   $0xfffffffffff0bdc0,%rax,%r11
add    %rbx,%r11
mov    %r11,%rax
shr    $0x5,%rax
movabs $0xa7c5ac471b47843,%rdx
5a 7c 0a
mul    %rdx
shr    $0x7,%rdx
lea    0x30(%rdx),%ebp
movzbl %dl,%eax
imul   $0xfffffffffffe7960,%rax,%rbx
add    %r11,%rbx
movabs $0x346dc5d63886594b,%rdx
c5 6d 34
mov    %rbx,%rax
mul    %rdx
mov    %bpl,0xb(%rsp)
shr    $0xb,%rdx
lea    0x30(%rdx),%eax
mov    %al,0xc(%rsp)
movzbl %dl,%eax
imul   $0xffffffffffffd8f0,%rax,%rbp
add    %rbx,%rbp
mov    %rbp,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rdx
9b c4 20
mul    %rdx
mov    %rdx,%rbx
shr    $0x4,%rbx
movzbl %bl,%eax
imul   $0xfffffffffffffc18,%rax,%r11
add    %rbp,%r11
mov    %r11,%rax
shr    $0x2,%rax
movabs $0x28f5c28f5c28f5c3,%rdx
c2 f5 28
mul    %rdx
lea    0x30(%rbx),%eax
mov    %al,0xd(%rsp)
shr    $0x2,%rdx
lea    0x30(%rdx),%eax
mov    %al,0xe(%rsp)
movzbl %dl,%eax
imul   $0xffffffffffffff9c,%rax,%rbx
add    %r11,%rbx
movabs $0xcccccccccccccccd,%rdx
cc cc cc
mov    %rbx,%rax
mul    %rdx
shr    $0x3,%rdx
lea    0x30(%rdx),%eax
mov    %al,0xf(%rsp)
add    %edx,%edx
lea    (%rdx,%rdx,4),%eax
sub    %eax,%ebx
add    $0x30,%bl
mov    %bl,0x10(%rsp)
add    $0x8,%ecx
movb   $0x0,0x11(%rsp)
lea    0x9(%rsp),%rax
mov    %rax,(%rsp)
mov    %r10d,%edx
call   1030 <draw_text@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @draw_int(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4, i64 %5, i64 %6) {
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i8
%17 = alloca [15 x i8]
%18 = alloca i32
store i32* %0, i32** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i64 %5, i64* %13
store i64 %6, i64* %14
store i64 10000000, i64* %15
store i32 0, i32* %18
%19 = load i64, i64* %14
%20 = urem i64 %19, 100000000
store i64 %20, i64* %14
br label %21
21: ; preds = %24, %7
%22 = load i64, i64* %15
%23 = icmp ugt i64 %22, 0
br i1 %23, label %24, label %47
24: ; preds = %21
%25 = load i64, i64* %14
%26 = load i64, i64* %15
%27 = udiv i64 %25, %26
%28 = trunc i64 %27 to i8
store i8 %28, i8* %16
%29 = load i8, i8* %16
%30 = zext i8 %29 to i32
%31 = add nsw i32 %30, 48
%32 = trunc i32 %31 to i8
%33 = load i32, i32* %18
%34 = add nsw i32 %33, 1
store i32 %34, i32* %18
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds [15 x i8], [15 x i8]* %17, i64 0, i64 %35
store i8 %32, i8* %36
%37 = load i64, i64* %14
%38 = load i8, i8* %16
%39 = zext i8 %38 to i64
%40 = load i64, i64* %15
%41 = mul i64 %39, %40
%42 = sub i64 %37, %41
store i64 %42, i64* %14
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
store i32 %44, i32* %11
%45 = load i64, i64* %15
%46 = udiv i64 %45, 10
store i64 %46, i64* %15
br label %21
47: ; preds = %21
%48 = load i32, i32* %18
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [15 x i8], [15 x i8]* %17, i64 0, i64 %49
store i8 0, i8* %50
%51 = load i32*, i32** %8
%52 = load i32, i32* %9
%53 = load i32, i32* %10
%54 = load i32, i32* %11
%55 = load i32, i32* %12
%56 = load i64, i64* %13
%57 = getelementptr inbounds [15 x i8], [15 x i8]* %17, i64 0, i64 0
%58 = call i32 @draw_text(i32* %51, i32 %52, i32 %53, i32 %54, i32 %55, i64 %56, i8* %57)
ret i32 0
}

LLVM IR (-O2):
define i32 @draw_int(i32* %0, i32 %1, i32 %2, i32 %3, i32 %4, i64 %5, i64 %6) {
%8 = alloca [15 x i8]
%9 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%10 = urem i64 %6, 100000000
%11 = trunc i64 %10 to i32
%12 = udiv i32 %11, 10000000
%13 = zext i32 %12 to i64
%14 = trunc i32 %12 to i8
%15 = or i8 %14, 48
store i8 %15, i8* %9
%16 = mul nsw i64 %13, -10000000
%17 = add nsw i64 %16, %10
%18 = udiv i64 %17, 1000000
%19 = trunc i64 %18 to i8
%20 = add i8 %19, 48
%21 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 1
store i8 %20, i8* %21
%22 = and i64 %18, 255
%23 = mul nsw i64 %22, -1000000
%24 = add nsw i64 %23, %17
%25 = udiv i64 %24, 100000
%26 = trunc i64 %25 to i8
%27 = add i8 %26, 48
%28 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 2
store i8 %27, i8* %28
%29 = and i64 %25, 255
%30 = mul nsw i64 %29, -100000
%31 = add nsw i64 %30, %24
%32 = udiv i64 %31, 10000
%33 = trunc i64 %32 to i8
%34 = add i8 %33, 48
%35 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 3
store i8 %34, i8* %35
%36 = and i64 %32, 255
%37 = mul nsw i64 %36, -10000
%38 = add nsw i64 %37, %31
%39 = udiv i64 %38, 1000
%40 = trunc i64 %39 to i8
%41 = add i8 %40, 48
%42 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 4
store i8 %41, i8* %42
%43 = and i64 %39, 255
%44 = mul nsw i64 %43, -1000
%45 = add nsw i64 %44, %38
%46 = udiv i64 %45, 100
%47 = trunc i64 %46 to i8
%48 = add i8 %47, 48
%49 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 5
store i8 %48, i8* %49
%50 = and i64 %46, 255
%51 = mul nsw i64 %50, -100
%52 = add nsw i64 %51, %45
%53 = udiv i64 %52, 10
%54 = trunc i64 %53 to i8
%55 = add i8 %54, 48
%56 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 6
store i8 %55, i8* %56
%57 = and i64 %53, 255
%58 = mul nsw i64 %57, -10
%59 = add nsw i64 %58, %52
%60 = trunc i64 %59 to i8
%61 = add i8 %60, 48
%62 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 7
store i8 %61, i8* %62
%63 = add i32 %3, 8
%64 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 8
store i8 0, i8* %64
%65 = call i32 @draw_text(i32* %0, i32 %1, i32 %2, i32 %63, i32 %4, i64 %5, i8* %9)
ret i32 0
}