#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 my_strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int my_putnbr_base(int nbr, char *base) {
  char str[12];
  int nbase;
  int i;
  i = 0;
  nbase = my_strlen(base);
  while (nbr > 0) {
    str[i] = base[nbr % nbase];
    nbr = nbr / nbase;
    ++i;
  }
  while (i--) {
    write(1, &str[i], 1);
  }
  return (nbr);
}


x86 assembly (clang, -O0):
<my_putnbr_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1185 <my_putnbr_base+0x65>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x20(%rbp)
mov    -0x30(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x24(%rbp),%rax
mov    %cl,-0x1c(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x20(%rbp)
mov    %eax,-0x4(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1142 <my_putnbr_base+0x22>
jmp    118a <my_putnbr_base+0x6a>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x24(%rbp)
cmp    $0x0,%eax
je     11ba <my_putnbr_base+0x9a>
movslq -0x24(%rbp),%rax
lea    -0x1c(%rbp),%rsi
add    %rax,%rsi
mov    $0x1,%edx
mov    %edx,%edi
call   1040 <write@plt>
jmp    118a <my_putnbr_base+0x6a>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_putnbr_base>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
mov    %rsi,%rdi
call   1030 <my_strlen@plt>
test   %r15d,%r15d
jle    11a1 <my_putnbr_base+0x81>
mov    %eax,%ecx
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%eax
cltd
idiv   %ecx
movzbl (%r14,%rdx,1),%edx
mov    %dl,0xc(%rsp,%rbx,1)
add    $0x1,%rbx
mov    %eax,%r15d
test   %eax,%eax
jg     1150 <my_putnbr_base+0x30>
test   %ebx,%ebx
je     11a1 <my_putnbr_base+0x81>
movslq %ebx,%rax
lea    (%rsp,%rax,1),%r14
add    $0xb,%r14
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
lea    (%r14,%rbp,1),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1040 <write@plt>
lea    -0x1(%rbp),%rax
add    %ebx,%ebp
cmp    $0x1,%ebp
mov    %rax,%rbp
jne    1180 <my_putnbr_base+0x60>
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @my_putnbr_base(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [12 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = call i32 @my_strlen(i8* %8)
store i32 %9, i32* %6
br label %10
10: ; preds = %13, %2
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = load i8*, i8** %4
%15 = load i32, i32* %3
%16 = load i32, i32* %6
%17 = srem i32 %15, %16
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %14, i64 %18
%20 = load i8, i8* %19
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 %22
store i8 %20, i8* %23
%24 = load i32, i32* %3
%25 = load i32, i32* %6
%26 = sdiv i32 %24, %25
store i32 %26, i32* %3
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %10
29: ; preds = %10
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 ne i32 %31, 0
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 %36
%38 = call i32 @write(i32 1, i8* %37, i32 1)
br label %30
39: ; preds = %30
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
define i32 @my_putnbr_base(i32 %0, i8* %1) {
%3 = alloca [12 x i8]
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @my_strlen(i8* %1)
%6 = icmp sgt i32 %0, 0
br i1 %6, label %13, label %31
7: ; preds = %13
%8 = trunc i64 %22 to i32
%9 = icmp eq i32 %8, 0
br i1 %9, label %31, label %10
10: ; preds = %7
%11 = shl i64 %22, 32
%12 = ashr exact i64 %11, 32
br label %24
13: ; preds = %2, %13
%14 = phi i64 [ %22, %13 ], [ 0, %2 ]
%15 = phi i32 [ %21, %13 ], [ %0, %2 ]
%16 = srem i32 %15, %5
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %1, i64 %17
%19 = load i8, i8* %18
%20 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 %14
store i8 %19, i8* %20
%21 = sdiv i32 %15, %5
%22 = add nuw i64 %14, 1
%23 = icmp sgt i32 %21, 0
br i1 %23, label %13, label %7
24: ; preds = %10, %24
%25 = phi i64 [ %12, %10 ], [ %26, %24 ]
%26 = add nsw i64 %25, -1
%27 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 %26
%28 = call i32 @write(i32 1, i8* %27, i32 1)
%29 = trunc i64 %26 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %24
31: ; preds = %24, %2, %7
%32 = phi i32 [ %21, %7 ], [ %0, %2 ], [ %21, %24 ]
ret i32 %32
}