#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*/ disp_text(char *, int, int /*<<< orphan*/);
char *num2string(long, int, int *, char *);
void disp_num(long num, int position, int width, int nfrac) {
  char tempc[17];
  char *text;
  int i, strlength;
  text = num2string(num, nfrac, &strlength, (char *)&tempc);
  if (strlength > width) {
    text = &tempc[16];
    for (i = 0; i < width; i++) {
      *--text = '*';
    }
  }
  while (width > strlength++) {
    *--text = ' ';
  }
  disp_text(text, position, 0);
}


x86 assembly (clang, -O0):
<disp_num>:
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    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x30(%rbp),%rcx
lea    -0x40(%rbp),%rdx
call   1030 <num2string@plt>
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    119e <disp_num+0x7e>
lea    -0x30(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1199 <disp_num+0x79>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x2a,-0x1(%rax)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    116c <disp_num+0x4c>
jmp    119e <disp_num+0x7e>
jmp    11a3 <disp_num+0x83>
mov    -0x10(%rbp),%eax
mov    -0x40(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x40(%rbp)
cmp    %ecx,%eax
jle    11d1 <disp_num+0xb1>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x20,-0x1(%rax)
jmp    11a3 <disp_num+0x83>
mov    -0x38(%rbp),%rdi
mov    -0xc(%rbp),%esi
xor    %edx,%edx
call   1040 <disp_text@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disp_num>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edx,%ebx
mov    %esi,%r14d
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rbp
mov    %ecx,%esi
mov    %rbp,%rcx
call   1040 <num2string@plt>
mov    0xc(%rsp),%r15d
cmp    %ebx,%r15d
jle    1184 <disp_num+0x54>
test   %ebx,%ebx
jle    117f <disp_num+0x4f>
lea    -0x1(%rbx),%eax
sub    %rax,%rbp
add    $0xf,%rbp
mov    %ebx,%edx
mov    %rbp,%rdi
mov    $0x2a,%esi
call   1030 <memset@plt>
mov    %rbp,%rax
jmp    1184 <disp_num+0x54>
lea    0x20(%rsp),%rax
lea    0x1(%r15),%ecx
mov    %ecx,0xc(%rsp)
cmp    %ebx,%r15d
jge    11b7 <disp_num+0x87>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x20,-0x1(%rax)
add    $0xffffffffffffffff,%rax
mov    0xc(%rsp),%ecx
lea    0x1(%rcx),%edx
mov    %edx,0xc(%rsp)
cmp    %ebx,%ecx
jl     11a0 <disp_num+0x70>
mov    %rax,%rdi
mov    %r14d,%esi
xor    %edx,%edx
call   1050 <disp_text@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @disp_num(i64 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [17 x i8]
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i64 %0, i64* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i64, i64* %5
%14 = load i32, i32* %8
%15 = bitcast [17 x i8]* %9 to i8*
%16 = call i8* @num2string(i64 %13, i32 %14, i32* %12, i8* %15)
store i8* %16, i8** %10
%17 = load i32, i32* %12
%18 = load i32, i32* %7
%19 = icmp sgt i32 %17, %18
br i1 %19, label %20, label %33
20: ; preds = %4
%21 = getelementptr inbounds [17 x i8], [17 x i8]* %9, i64 0, i64 16
store i8* %21, i8** %10
store i32 0, i32* %11
br label %22
22: ; preds = %29, %20
%23 = load i32, i32* %11
%24 = load i32, i32* %7
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %32
26: ; preds = %22
%27 = load i8*, i8** %10
%28 = getelementptr inbounds i8, i8* %27, i32 -1
store i8* %28, i8** %10
store i8 42, i8* %28
br label %29
29: ; preds = %26
%30 = load i32, i32* %11
%31 = add nsw i32 %30, 1
store i32 %31, i32* %11
br label %22
32: ; preds = %22
br label %33
33: ; preds = %32, %4
br label %34
34: ; preds = %39, %33
%35 = load i32, i32* %7
%36 = load i32, i32* %12
%37 = add nsw i32 %36, 1
store i32 %37, i32* %12
%38 = icmp sgt i32 %35, %36
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = load i8*, i8** %10
%41 = getelementptr inbounds i8, i8* %40, i32 -1
store i8* %41, i8** %10
store i8 32, i8* %41
br label %34
42: ; preds = %34
%43 = load i8*, i8** %10
%44 = load i32, i32* %6
%45 = call i32 @disp_text(i8* %43, i32 %44, i32 0)
ret void
}

LLVM IR (-O2):
define void @disp_num(i64 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [17 x i8]
%6 = alloca i32
%7 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%8 = bitcast i32* %6 to i8*
%9 = call i8* @num2string(i64 %0, i32 %3, i32* %6, i8* %7)
%10 = load i32, i32* %6
%11 = icmp sgt i32 %10, %2
br i1 %11, label %12, label %21
12: ; preds = %4
%13 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 16
%14 = icmp sgt i32 %2, 0
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = add nsw i32 %2, -1
%17 = zext i32 %16 to i64
%18 = sub nsw i64 15, %17
%19 = getelementptr [17 x i8], [17 x i8]* %5, i64 0, i64 %18
%20 = zext i32 %2 to i64
br label %21
21: ; preds = %15, %12, %4
%22 = phi i8* [ %9, %4 ], [ %13, %12 ], [ %19, %15 ]
%23 = add nsw i32 %10, 1
store i32 %23, i32* %6
%24 = icmp slt i32 %10, %2
br i1 %24, label %25, label %31
25: ; preds = %21, %25
%26 = phi i8* [ %27, %25 ], [ %22, %21 ]
%27 = getelementptr inbounds i8, i8* %26, i64 -1
store i8 32, i8* %27
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
%30 = icmp slt i32 %28, %2
br i1 %30, label %25, label %31
31: ; preds = %25, %21
%32 = phi i8* [ %22, %21 ], [ %27, %25 ]
%33 = call i32 @disp_text(i8* %32, i32 %1, i32 0)
ret void
}