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

/* Variables and functions */
char *malloc(int);
int my_countnb_b(int, int /*<<< orphan*/);
int /*<<< orphan*/ my_strlen(char *);
char *my_strnbr_b(int, char *, char *, int /*<<< orphan*/);
char *my_strnbr(int nbr, char *base) {
  char *tab;
  if (nbr == 0)
    return ("0");
  if (nbr < 0) {
    tab = malloc(sizeof(tab) * my_countnb_b(nbr, my_strlen(base)) + 1);
    if (tab == NULL)
      return (NULL);
    tab[0] = '-';
    tab = my_strnbr_b(nbr, tab + 1, base, my_strlen(base));
  } else {
    tab = malloc(sizeof(tab) * my_countnb_b(nbr, my_strlen(base)));
    if (tab == NULL)
      return (NULL);
    tab = my_strnbr_b(nbr, tab, base, my_strlen(base));
  }
  return (tab);
}


x86 assembly (clang, -O0):
<my_strnbr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1169 <my_strnbr+0x29>
lea    0xea0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    127d <my_strnbr+0x13d>
cmpl   $0x0,-0xc(%rbp)
jge    11fe <my_strnbr+0xbe>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
call   1040 <my_countnb_b@plt>
cltq
shl    $0x3,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b9 <my_strnbr+0x79>
movq   $0x0,-0x8(%rbp)
jmp    127d <my_strnbr+0x13d>
mov    -0x20(%rbp),%rax
movb   $0x2d,(%rax)
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
call   1060 <my_strnbr_b@plt>
mov    %rax,-0x20(%rbp)
jmp    1275 <my_strnbr+0x135>
mov    -0xc(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    -0x40(%rbp),%edi
mov    %eax,%esi
call   1040 <my_countnb_b@plt>
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1240 <my_strnbr+0x100>
movq   $0x0,-0x8(%rbp)
jmp    127d <my_strnbr+0x13d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    %eax,%ecx
call   1060 <my_strnbr_b@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_strnbr>:
push   %rbp
push   %r14
push   %rbx
test   %edi,%edi
je     1176 <my_strnbr+0x36>
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rsi,%rdi
call   1030 <my_strlen@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <my_countnb_b@plt>
shl    $0x3,%eax
test   %ebp,%ebp
js     117f <my_strnbr+0x3f>
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1198 <my_strnbr+0x58>
jmp    11b3 <my_strnbr+0x73>
lea    0xe83(%rip),%rax
jmp    11b5 <my_strnbr+0x75>
or     $0x1,%eax
mov    %eax,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11b3 <my_strnbr+0x73>
mov    %rax,%rbx
movb   $0x2d,(%rax)
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <my_strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %eax,%ecx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <my_strnbr_b@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
define i8* @my_strnbr(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3
br label %57
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %36
13: ; preds = %10
%14 = load i32, i32* %4
%15 = load i8*, i8** %5
%16 = call i32 @my_strlen(i8* %15)
%17 = call i32 @my_countnb_b(i32 %14, i32 %16)
%18 = sext i32 %17 to i64
%19 = mul i64 8, %18
%20 = add i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = call i8* @malloc(i32 %21)
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %13
store i8* null, i8** %3
br label %57
26: ; preds = %13
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i64 0
store i8 45, i8* %28
%29 = load i32, i32* %4
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8*, i8** %5
%33 = load i8*, i8** %5
%34 = call i32 @my_strlen(i8* %33)
%35 = call i8* @my_strnbr_b(i32 %29, i8* %31, i8* %32, i32 %34)
store i8* %35, i8** %6
br label %55
36: ; preds = %10
%37 = load i32, i32* %4
%38 = load i8*, i8** %5
%39 = call i32 @my_strlen(i8* %38)
%40 = call i32 @my_countnb_b(i32 %37, i32 %39)
%41 = sext i32 %40 to i64
%42 = mul i64 8, %41
%43 = trunc i64 %42 to i32
%44 = call i8* @malloc(i32 %43)
store i8* %44, i8** %6
%45 = load i8*, i8** %6
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %48
47: ; preds = %36
store i8* null, i8** %3
br label %57
48: ; preds = %36
%49 = load i32, i32* %4
%50 = load i8*, i8** %6
%51 = load i8*, i8** %5
%52 = load i8*, i8** %5
%53 = call i32 @my_strlen(i8* %52)
%54 = call i8* @my_strnbr_b(i32 %49, i8* %50, i8* %51, i32 %53)
store i8* %54, i8** %6
br label %55
55: ; preds = %48, %26
%56 = load i8*, i8** %6
store i8* %56, i8** %3
br label %57
57: ; preds = %55, %47, %25, %9
%58 = load i8*, i8** %3
ret i8* %58
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
define i8* @my_strnbr(i32 %0, i8* %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %22, label %4
4: ; preds = %2
%5 = icmp slt i32 %0, 0
%6 = tail call i32 @my_strlen(i8* %1)
%7 = tail call i32 @my_countnb_b(i32 %0, i32 %6)
%8 = shl i32 %7, 3
br i1 %5, label %9, label %15
9: ; preds = %4
%10 = or i32 %8, 1
%11 = tail call i8* @malloc(i32 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %22, label %13
13: ; preds = %9
store i8 45, i8* %11
%14 = getelementptr inbounds i8, i8* %11, i64 1
br label %18
15: ; preds = %4
%16 = tail call i8* @malloc(i32 %8)
%17 = icmp eq i8* %16, null
br i1 %17, label %22, label %18
18: ; preds = %15, %13
%19 = phi i8* [ %14, %13 ], [ %16, %15 ]
%20 = tail call i32 @my_strlen(i8* %1)
%21 = tail call i8* @my_strnbr_b(i32 %0, i8* %19, i8* %1, i32 %20)
br label %22
22: ; preds = %18, %15, %9, %2
%23 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %2 ], [ null, %9 ], [ null, %15 ], [ %21, %18 ]
ret i8* %23
}