#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*/ my_putchar(char);
unsigned int my_strlen(char *);
int my_put_nbr_hexa_P(unsigned long nb, char *base) {
  long bin;
  long result;
  int cmp;
  unsigned int len;
  cmp = 0;
  bin = 1;
  len = my_strlen(base);
  while (nb / bin >= len)
    bin *= len;
  while (bin > 0) {
    result = (nb / bin) % len;
    my_putchar(base[result]);
    cmp++;
    bin /= len;
  }
  return (cmp);
}


x86 assembly (clang, -O0):
<my_put_nbr_hexa_P>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    -0x28(%rbp),%ecx
cmp    %rcx,%rax
jb     1174 <my_put_nbr_hexa_P+0x54>
mov    -0x28(%rbp),%eax
imul   -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    114b <my_put_nbr_hexa_P+0x2b>
jmp    1179 <my_put_nbr_hexa_P+0x59>
cmpq   $0x0,-0x18(%rbp)
jle    11cd <my_put_nbr_hexa_P+0xad>
mov    -0x8(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    -0x28(%rbp),%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <my_putchar@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
jmp    1179 <my_put_nbr_hexa_P+0x59>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_put_nbr_hexa_P>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <my_strlen@plt>
mov    %eax,%r12d
xor    %ebp,%ebp
mov    $0x1,%ebx
cmp    %r15,%r12
ja     11a3 <my_put_nbr_hexa_P+0x83>
jmp    115d <my_put_nbr_hexa_P+0x3d>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rax
xor    %edx,%edx
div    %rbx
cmp    %r12,%rax
jb     1179 <my_put_nbr_hexa_P+0x59>
imul   %r12,%rbx
mov    %r15,%rax
or     %rbx,%rax
shr    $0x20,%rax
jne    1150 <my_put_nbr_hexa_P+0x30>
mov    %r15d,%eax
xor    %edx,%edx
div    %ebx
cmp    %r12,%rax
jae    115d <my_put_nbr_hexa_P+0x3d>
xor    %ebp,%ebp
test   %rbx,%rbx
jne    11a3 <my_put_nbr_hexa_P+0x83>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rax
cqto
idiv   %r12
mov    %rax,%rbx
add    $0x1,%ebp
test   %rbx,%rbx
jle    1180 <my_put_nbr_hexa_P+0x60>
mov    %r15,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     11c0 <my_put_nbr_hexa_P+0xa0>
mov    %r15,%rax
xor    %edx,%edx
div    %rbx
jmp    11c7 <my_put_nbr_hexa_P+0xa7>
nopl   0x0(%rax)
mov    %r15d,%eax
xor    %edx,%edx
div    %ebx
mov    %rax,%rcx
shr    $0x20,%rcx
je     11e0 <my_put_nbr_hexa_P+0xc0>
xor    %edx,%edx
div    %r12
jmp    11e5 <my_put_nbr_hexa_P+0xc5>
nopw   0x0(%rax,%rax,1)
xor    %edx,%edx
div    %r12d
movsbl (%r14,%rdx,1),%edi
call   1040 <my_putchar@plt>
mov    %rbx,%rax
shr    $0x20,%rax
jne    1190 <my_put_nbr_hexa_P+0x70>
mov    %ebx,%eax
xor    %edx,%edx
div    %r12d
mov    %eax,%ebx
jmp    119b <my_put_nbr_hexa_P+0x7b>

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

LLVM IR (-O2):
define i32 @my_put_nbr_hexa_P(i64 %0, i8* %1) {
%3 = tail call i32 @my_strlen(i8* %1)
%4 = zext i32 %3 to i64
%5 = icmp ugt i64 %4, %0
br i1 %5, label %8, label %10
6: ; preds = %10
%7 = icmp eq i64 %12, 0
br i1 %7, label %26, label %8
8: ; preds = %2, %6
%9 = phi i64 [ 1, %2 ], [ %12, %6 ]
br label %15
10: ; preds = %2, %10
%11 = phi i64 [ %12, %10 ], [ 1, %2 ]
%12 = mul nuw nsw i64 %11, %4
%13 = udiv i64 %0, %12
%14 = icmp ult i64 %13, %4
br i1 %14, label %6, label %10
15: ; preds = %8, %15
%16 = phi i64 [ %24, %15 ], [ %9, %8 ]
%17 = phi i32 [ %23, %15 ], [ 0, %8 ]
%18 = udiv i64 %0, %16
%19 = urem i64 %18, %4
%20 = getelementptr inbounds i8, i8* %1, i64 %19
%21 = load i8, i8* %20
%22 = tail call i32 @my_putchar(i8 signext %21)
%23 = add nuw nsw i32 %17, 1
%24 = sdiv i64 %16, %4
%25 = icmp sgt i64 %24, 0
br i1 %25, label %15, label %26
26: ; preds = %15, %6
%27 = phi i32 [ 0, %6 ], [ %23, %15 ]
ret i32 %27
}