#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*/ putchar(char);
int PUTL(unsigned long u, int base, int width, int fill_char) {
  int r = 0;
  static char obuf[32];
  char *t;
  t = obuf;
  do {
    *t++ = "0123456789abcdef"[u % base];
    u /= base;
    width--;
  } while (u > 0);
  while (width-- > 0) {
    putchar(fill_char);
    r++;
  }
  while (t != obuf) {
    putchar(*--t);
    r++;
  }
  return r;
}


x86 assembly (clang, -O0):
<PUTL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0x2f0d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
xor    %edx,%edx
div    %rcx
lea    0xeb5(%rip),%rax
mov    (%rax,%rdx,1),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
movslq -0xc(%rbp),%rcx
mov    -0x8(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
ja     1137 <PUTL+0x27>
jmp    1189 <PUTL+0x79>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
cmp    $0x0,%eax
jle    11b6 <PUTL+0xa6>
mov    -0x14(%rbp),%eax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1189 <PUTL+0x79>
jmp    11bb <PUTL+0xab>
lea    0x2e7e(%rip),%rax
cmp    %rax,-0x20(%rbp)
je     11f2 <PUTL+0xe2>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
movsbl -0x1(%rax),%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bb <PUTL+0xab>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PUTL>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
movslq %esi,%r8
xor    %r13d,%r13d
lea    0xed5(%rip),%r9
lea    0x2f0e(%rip),%r15
mov    %edx,%ebp
jmp    1161 <PUTL+0x51>
cs nopw 0x0(%rax,%rax,1)
mov    %rdi,%rax
xor    %edx,%edx
div    %r8
movzbl (%rdx,%r9,1),%edx
mov    %dl,0x0(%r13,%r15,1)
add    $0xffffffff,%ebp
add    $0x1,%r13
cmp    %r8,%rdi
mov    %rax,%rdi
jb     1175 <PUTL+0x65>
mov    %rdi,%rax
or     %r8,%rax
shr    $0x20,%rax
jne    1140 <PUTL+0x30>
mov    %edi,%eax
xor    %edx,%edx
div    %esi
jmp    1148 <PUTL+0x38>
mov    %r14d,%eax
sub    %r13,%rax
lea    0x1(%rax),%r12
xor    %edx,%edx
cmp    $0x2,%r12d
jl     11c2 <PUTL+0xb2>
test   %ebp,%ebp
mov    $0x1,%ebx
cmovg  %ebx,%ebp
sub    %ebp,%r14d
add    $0x1,%r14d
sub    %r13,%r14
test   %eax,%eax
cmovle %eax,%ebx
movsbl %cl,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
cmp    %ebx,%r12d
jne    11b0 <PUTL+0xa0>
mov    %r14d,%edx
mov    %edx,%ebp
test   %r13,%r13
je     11e4 <PUTL+0xd4>
mov    %r13,%rbx
nopl   0x0(%rax)
movsbl -0x1(%rbx,%r15,1),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
jne    11d0 <PUTL+0xc0>
add    %r13d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PUTL.obuf = internal global [32 x i8] zeroinitializer
@.str = [17 x i8] c"0123456789abcdef\00"
define i32 @PUTL(i64 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i64 %0, i64* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @PUTL.obuf, i64 0, i64 0), i8** %10
br label %11
11: ; preds = %26, %4
%12 = load i64, i64* %5
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = urem i64 %12, %14
%16 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = load i8*, i8** %10
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %10
store i8 %17, i8* %18
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = load i64, i64* %5
%23 = udiv i64 %22, %21
store i64 %23, i64* %5
%24 = load i32, i32* %7
%25 = add nsw i32 %24, -1
store i32 %25, i32* %7
br label %26
26: ; preds = %11
%27 = load i64, i64* %5
%28 = icmp ugt i64 %27, 0
br i1 %28, label %11, label %29
29: ; preds = %26
br label %30
30: ; preds = %34, %29
%31 = load i32, i32* %7
%32 = add nsw i32 %31, -1
store i32 %32, i32* %7
%33 = icmp sgt i32 %31, 0
br i1 %33, label %34, label %40
34: ; preds = %30
%35 = load i32, i32* %8
%36 = trunc i32 %35 to i8
%37 = call i32 @putchar(i8 signext %36)
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
br label %30
40: ; preds = %30
br label %41
41: ; preds = %44, %40
%42 = load i8*, i8** %10
%43 = icmp ne i8* %42, getelementptr inbounds ([32 x i8], [32 x i8]* @PUTL.obuf, i64 0, i64 0)
br i1 %43, label %44, label %51
44: ; preds = %41
%45 = load i8*, i8** %10
%46 = getelementptr inbounds i8, i8* %45, i32 -1
store i8* %46, i8** %10
%47 = load i8, i8* %46
%48 = call i32 @putchar(i8 signext %47)
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
br label %41
51: ; preds = %41
%52 = load i32, i32* %9
ret i32 %52
}

LLVM IR (-O2):
@PUTL.obuf = internal global [32 x i8] zeroinitializer
@.str = [17 x i8] c"0123456789abcdef\00"
define i32 @PUTL(i64 %0, i32 %1, i32 %2, i32 %3) {
%5 = sext i32 %1 to i64
br label %6
6: ; preds = %6, %4
%7 = phi i32 [ %2, %4 ], [ %15, %6 ]
%8 = phi i64 [ %0, %4 ], [ %14, %6 ]
%9 = phi i8* [ getelementptr inbounds ([32 x i8], [32 x i8]* @PUTL.obuf, i64 0, i64 0), %4 ], [ %13, %6 ]
%10 = urem i64 %8, %5
%11 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %12, i8* %9
%14 = udiv i64 %8, %5
%15 = add nsw i32 %7, -1
%16 = icmp ult i64 %8, %5
br i1 %16, label %17, label %6
17: ; preds = %6
%18 = ptrtoint i8* %13 to i64
%19 = icmp sgt i32 %7, 1
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = trunc i32 %3 to i8
%22 = call i32 @llvm.smin.i32(i32 %15, i32 1)
%23 = sub nuw nsw i32 %7, %22
br label %30
24: ; preds = %30, %17
%25 = phi i32 [ 0, %17 ], [ %23, %30 ]
%26 = icmp eq i8* %13, getelementptr inbounds ([32 x i8], [32 x i8]* @PUTL.obuf, i64 0, i64 0)
br i1 %26, label %43, label %27
27: ; preds = %24
%28 = trunc i64 %18 to i32
%29 = add i32 %25, %28
br label %35
30: ; preds = %20, %30
%31 = phi i32 [ 0, %20 ], [ %33, %30 ]
%32 = tail call i32 @putchar(i8 signext %21)
%33 = add nuw nsw i32 %31, 1
%34 = icmp eq i32 %33, %23
br i1 %34, label %24, label %30
35: ; preds = %27, %35
%36 = phi i8* [ %37, %35 ], [ %13, %27 ]
%37 = getelementptr inbounds i8, i8* %36, i64 -1
%38 = load i8, i8* %37
%39 = tail call i32 @putchar(i8 signext %38)
%40 = icmp eq i8* %37, getelementptr inbounds ([32 x i8], [32 x i8]* @PUTL.obuf, i64 0, i64 0)
br i1 %40, label %41, label %35
41: ; preds = %35
%42 = sub i32 %29, ptrtoint ([32 x i8]* @PUTL.obuf to i32)
br label %43
43: ; preds = %41, %24
%44 = phi i32 [ %25, %24 ], [ %42, %41 ]
ret i32 %44
}