#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 */
char hex2char(int);
int stringify(char *s, int digits, int divisor, int value, int shift) {
  int i = value;
  if (digits > 1) {
    i = stringify(s + 1, (digits - 1), divisor, value, shift);
  }
  s[0] = hex2char(i & (divisor - 1));
  return (i >> shift);
}


x86 assembly (clang, -O0):
<stringify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0xc(%rbp)
jle    1169 <stringify+0x49>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1030 <stringify@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
and    %eax,%edi
call   1040 <hex2char@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%ecx
sar    %cl,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringify>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %ecx,%ebp
mov    %edx,%ebx
mov    %rdi,%r15
cmp    $0x2,%esi
jl     114b <stringify+0x2b>
lea    0x1(%r15),%rdi
add    $0xffffffff,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r14d,%r8d
call   1030 <stringify@plt>
mov    %eax,%ebp
add    $0xffffffff,%ebx
and    %ebp,%ebx
mov    %ebx,%edi
call   1040 <hex2char@plt>
mov    %al,(%r15)
mov    %r14d,%ecx
sar    %cl,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @stringify(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load i32, i32* %9
store i32 %12, i32* %11
%13 = load i32, i32* %7
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %24
15: ; preds = %5
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i32, i32* %7
%19 = sub nsw i32 %18, 1
%20 = load i32, i32* %8
%21 = load i32, i32* %9
%22 = load i32, i32* %10
%23 = call i32 @stringify(i8* %17, i32 %19, i32 %20, i32 %21, i32 %22)
store i32 %23, i32* %11
br label %24
24: ; preds = %15, %5
%25 = load i32, i32* %11
%26 = load i32, i32* %8
%27 = sub nsw i32 %26, 1
%28 = and i32 %25, %27
%29 = call signext i8 @hex2char(i32 %28)
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 0
store i8 %29, i8* %31
%32 = load i32, i32* %11
%33 = load i32, i32* %10
%34 = ashr i32 %32, %33
ret i32 %34
}

LLVM IR (-O2):
define i32 @stringify(i8* nocapture writeonly %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp sgt i32 %1, 1
br i1 %6, label %7, label %11
7: ; preds = %5
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = add nsw i32 %1, -1
%10 = tail call i32 @stringify(i8* %8, i32 %9, i32 %2, i32 %3, i32 %4)
br label %11
11: ; preds = %7, %5
%12 = phi i32 [ %10, %7 ], [ %3, %5 ]
%13 = add nsw i32 %2, -1
%14 = and i32 %12, %13
%15 = tail call signext i8 @hex2char(i32 %14)
store i8 %15, i8* %0
%16 = ashr i32 %12, %4
ret i32 %16
}