#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);
int my_put_nbr_long(long nb) {
  int cmp;
  long c;
  char *base;
  cmp = 0;
  c = 1;
  base = "0123456789";
  if (nb < 0) {
    my_putchar('-');
    nb *= -1;
    cmp++;
  }
  while (nb / c >= 10)
    c *= 10;
  while (c > 0) {
    my_putchar(base[nb / c % 10]);
    cmp++;
    c /= 10;
  }
  return (cmp);
}


x86 assembly (clang, -O0):
<my_put_nbr_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x1,-0x18(%rbp)
lea    0xece(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    115d <my_put_nbr_long+0x4d>
mov    $0x2d,%edi
call   1030 <my_putchar@plt>
imul   $0xffffffffffffffff,-0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1162 <my_put_nbr_long+0x52>
mov    -0x8(%rbp),%rax
cqto
idivq  -0x18(%rbp)
cmp    $0xa,%rax
jl     1184 <my_put_nbr_long+0x74>
imul   $0xa,-0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1162 <my_put_nbr_long+0x52>
jmp    1189 <my_put_nbr_long+0x79>
cmpq   $0x0,-0x18(%rbp)
jle    11dd <my_put_nbr_long+0xcd>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
cqto
idivq  -0x18(%rbp)
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    -0x28(%rbp),%rax
movsbl (%rax,%rdx,1),%edi
call   1030 <my_putchar@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
jmp    1189 <my_put_nbr_long+0x79>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_put_nbr_long>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebp,%ebp
test   %rdi,%rdi
jns    1130 <my_put_nbr_long+0x20>
mov    $0x2d,%edi
call   1030 <my_putchar@plt>
neg    %r14
mov    $0x1,%ebp
mov    $0x1,%ebx
cmp    $0xa,%r14
jb     11f3 <my_put_nbr_long+0xe3>
jmp    1162 <my_put_nbr_long+0x52>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rax
cqto
idiv   %rbx
cmp    $0x9,%rax
jle    11f3 <my_put_nbr_long+0xe3>
add    %rbx,%rbx
lea    (%rbx,%rbx,4),%rbx
mov    %r14,%rax
or     %rbx,%rax
shr    $0x20,%rax
jne    1150 <my_put_nbr_long+0x40>
mov    %r14d,%eax
xor    %edx,%edx
div    %ebx
cmp    $0x9,%rax
jg     1162 <my_put_nbr_long+0x52>
jmp    11f3 <my_put_nbr_long+0xe3>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rax
cqto
idiv   %rbx
mov    %rax,%rcx
movabs $0x6666666666666667,%rdx
66 66 66
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%rdx
add    %rax,%rdx
add    %rdx,%rdx
lea    (%rdx,%rdx,4),%rax
sub    %rax,%rcx
lea    0xe36(%rip),%rax
movsbl (%rax,%rcx,1),%edi
call   1030 <my_putchar@plt>
add    $0x1,%ebp
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mov    %rbx,%rax
mul    %rcx
shr    $0x3,%rdx
cmp    $0x9,%rbx
mov    %rdx,%rbx
jbe    120a <my_put_nbr_long+0xfa>
mov    %r14,%rax
or     %rbx,%rax
shr    $0x20,%rax
jne    1190 <my_put_nbr_long+0x80>
mov    %r14d,%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%ecx
jmp    119b <my_put_nbr_long+0x8b>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"0123456789\00"
define i32 @my_put_nbr_long(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
store i64 %0, i64* %2
store i32 0, i32* %3
store i64 1, i64* %4
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = load i64, i64* %2
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = call i32 @my_putchar(i8 signext 45)
%10 = load i64, i64* %2
%11 = mul nsw i64 %10, -1
store i64 %11, i64* %2
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
store i32 %13, i32* %3
br label %14
14: ; preds = %8, %1
br label %15
15: ; preds = %20, %14
%16 = load i64, i64* %2
%17 = load i64, i64* %4
%18 = sdiv i64 %16, %17
%19 = icmp sge i64 %18, 10
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i64, i64* %4
%22 = mul nsw i64 %21, 10
store i64 %22, i64* %4
br label %15
23: ; preds = %15
br label %24
24: ; preds = %27, %23
%25 = load i64, i64* %4
%26 = icmp sgt i64 %25, 0
br i1 %26, label %27, label %40
27: ; preds = %24
%28 = load i8*, i8** %5
%29 = load i64, i64* %2
%30 = load i64, i64* %4
%31 = sdiv i64 %29, %30
%32 = srem i64 %31, 10
%33 = getelementptr inbounds i8, i8* %28, i64 %32
%34 = load i8, i8* %33
%35 = call i32 @my_putchar(i8 signext %34)
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
%38 = load i64, i64* %4
%39 = sdiv i64 %38, 10
store i64 %39, i64* %4
br label %24
40: ; preds = %24
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [11 x i8] c"0123456789\00"
define i32 @my_put_nbr_long(i64 %0) {
%2 = icmp slt i64 %0, 0
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = tail call i32 @my_putchar(i8 signext 45)
%5 = sub nsw i64 0, %0
br label %6
6: ; preds = %3, %1
%7 = phi i32 [ 1, %3 ], [ 0, %1 ]
%8 = phi i64 [ %5, %3 ], [ %0, %1 ]
%9 = icmp ugt i64 %8, 9
br i1 %9, label %10, label %15
10: ; preds = %6, %10
%11 = phi i64 [ %12, %10 ], [ 1, %6 ]
%12 = mul nuw nsw i64 %11, 10
%13 = sdiv i64 %8, %12
%14 = icmp sgt i64 %13, 9
br i1 %14, label %10, label %15
15: ; preds = %10, %6
%16 = phi i64 [ 1, %6 ], [ %12, %10 ]
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ %26, %17 ], [ %16, %15 ]
%19 = phi i32 [ %25, %17 ], [ %7, %15 ]
%20 = sdiv i64 %8, %18
%21 = srem i64 %20, 10
%22 = getelementptr inbounds [11 x i8], [11 x i8]* @.str, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = tail call i32 @my_putchar(i8 signext %23)
%25 = add nuw nsw i32 %19, 1
%26 = udiv i64 %18, 10
%27 = icmp ult i64 %18, 10
br i1 %27, label %28, label %17
28: ; preds = %17
ret i32 %25
}