#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 /*<<< orphan*/ buf;

/* Variables and functions */
int _add(char *);
_conv(int n, int digits, char pad) {
  static char buf[10];
  register char *p;
  for (p = buf + sizeof(buf) - 2; n > 0 && p > buf; n /= 10, --digits)
    *p-- = n % 10 + '0';
  while (p > buf && digits-- > 0)
    *p-- = pad;
  return (_add(++p));
}


x86 assembly (clang, -O0):
<_conv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
lea    0x2eff(%rip),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x19(%rbp)
jle    1152 <_conv+0x42>
lea    0x2ee1(%rip),%rax
cmp    %rax,-0x18(%rbp)
seta   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1162 <_conv+0x52>
jmp    119f <_conv+0x8f>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1132 <_conv+0x22>
jmp    11a4 <_conv+0x94>
xor    %eax,%eax
lea    0x2e7c(%rip),%rcx
cmp    %rcx,-0x18(%rbp)
mov    %al,-0x1a(%rbp)
jbe    11ce <_conv+0xbe>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
setg   %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    11de <_conv+0xce>
jmp    11f7 <_conv+0xe7>
mov    -0x9(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    11a4 <_conv+0x94>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x18(%rbp)
call   1030 <_add@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_conv>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
lea    0x2f0b(%rip),%rbx
test   %edi,%edi
jle    116f <_conv+0x4f>
mov    $0xcccccccd,%r9d
lea    0x2ef2(%rip),%r8
nop
mov    %edi,%eax
mov    %edi,%edi
imul   %r9,%rdi
shr    $0x23,%rdi
lea    (%rdi,%rdi,1),%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%esi
sub    %ecx,%esi
or     $0x30,%sil
mov    %sil,(%rbx)
add    $0xffffffffffffffff,%rbx
add    $0xffffffff,%r14d
cmp    $0xa,%eax
jb     116f <_conv+0x4f>
cmp    %r8,%rbx
ja     1140 <_conv+0x20>
lea    0x2ebb(%rip),%rax
cmp    %rax,%rbx
jbe    11b3 <_conv+0x93>
test   %r14d,%r14d
jle    11b3 <_conv+0x93>
not    %rax
add    %rbx,%rax
add    $0xffffffff,%r14d
cmp    %rax,%r14
cmovae %rax,%r14
test   %rax,%rax
cmove  %rax,%r14
mov    %rbx,%rdi
sub    %r14,%rdi
lea    0x1(%r14),%rax
movzbl %dl,%esi
mov    %rax,%rdx
call   1040 <memset@plt>
not    %r14
add    %r14,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <_add@plt>

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

LLVM IR (-O2):
@_conv.buf = internal global [10 x i8] zeroinitializer
define i32 @_conv(i32 %0, i32 %1, i8 signext %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %24, label %5
5: ; preds = %24, %3
%6 = phi i32 [ %1, %3 ], [ %33, %24 ]
%7 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @_conv.buf, i64 0, i64 8), %3 ], [ %31, %24 ]
%8 = icmp ugt i8* %7, getelementptr inbounds ([10 x i8], [10 x i8]* @_conv.buf, i64 0, i64 0)
%9 = icmp sgt i32 %6, 0
%10 = select i1 %8, i1 %9, i1 false
br i1 %10, label %11, label %37
11: ; preds = %5
%12 = ptrtoint i8* %7 to i64
%13 = add i64 %12, xor (i64 ptrtoint ([10 x i8]* @_conv.buf to i64), i64 -1)
%14 = add nsw i32 %6, -1
%15 = zext i32 %14 to i64
%16 = icmp eq i64 %13, 0
%17 = call i64 @llvm.umin.i64(i64 %15, i64 %13)
%18 = select i1 %16, i64 0, i64 %17
%19 = sub nsw i64 0, %18
%20 = getelementptr i8, i8* %7, i64 %19
%21 = add nuw nsw i64 %18, 1
%22 = xor i64 %18, -1
%23 = getelementptr i8, i8* %7, i64 %22
br label %37
24: ; preds = %3, %24
%25 = phi i8* [ %31, %24 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @_conv.buf, i64 0, i64 8), %3 ]
%26 = phi i32 [ %32, %24 ], [ %0, %3 ]
%27 = phi i32 [ %33, %24 ], [ %1, %3 ]
%28 = urem i32 %26, 10
%29 = trunc i32 %28 to i8
%30 = or i8 %29, 48
%31 = getelementptr inbounds i8, i8* %25, i64 -1
store i8 %30, i8* %25
%32 = udiv i32 %26, 10
%33 = add nsw i32 %27, -1
%34 = icmp ugt i32 %26, 9
%35 = icmp ugt i8* %31, getelementptr inbounds ([10 x i8], [10 x i8]* @_conv.buf, i64 0, i64 0)
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %24, label %5
37: ; preds = %11, %5
%38 = phi i8* [ %7, %5 ], [ %23, %11 ]
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = tail call i32 @_add(i8* %39)
ret i32 %40
}