#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rever(char *);
void my_itoa(int n, char s[]) {
  if (s == NULL) {
    printf("error: the argument of my_atoi is NULL!");
    exit(0);
  }
  int i = 0;
  int sign = 0;
  if ((sign = n) < 0)
    n = -n;
  do {
    s[i++] = n % 10 + '0';
  } while ((n /= 10) > 0);
  if (sign < 0)
    s[i++] = '-';
  s[i] = '\0';
  rever(s);
}


x86 assembly (clang, -O0):
<my_itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115d <my_itoa+0x2d>
lea    0xeaf(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1182 <my_itoa+0x52>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1187 <my_itoa+0x57>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jg     1187 <my_itoa+0x57>
cmpl   $0x0,-0x18(%rbp)
jge    11e1 <my_itoa+0xb1>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1040 <rever@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_itoa>:
push   %rax
test   %rsi,%rsi
je     1191 <my_itoa+0x61>
mov    %edi,%ecx
neg    %ecx
cmovs  %edi,%ecx
xor    %eax,%eax
nop
movslq %ecx,%r8
imul   $0x66666667,%r8,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,1),%edx
lea    (%rdx,%rdx,4),%r9d
mov    %r8d,%edx
sub    %r9d,%edx
add    $0x30,%dl
mov    %dl,(%rsi,%rax,1)
add    $0x1,%rax
cmp    $0x9,%r8d
jg     1140 <my_itoa+0x10>
test   %edi,%edi
jns    1182 <my_itoa+0x52>
mov    %eax,%ecx
add    $0x1,%rax
movb   $0x2d,(%rsi,%rcx,1)
cltq
movb   $0x0,(%rsi,%rax,1)
mov    %rsi,%rdi
pop    %rax
jmp    1040 <rever@plt>
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [40 x i8] c"error: the argument of my_atoi is NULL!\00"
define void @my_itoa(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %2
store i32 0, i32* %5
store i32 0, i32* %6
%13 = load i32, i32* %3
store i32 %13, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* %3
%17 = sub nsw i32 0, %16
store i32 %17, i32* %3
br label %18
18: ; preds = %15, %12
br label %19
19: ; preds = %29, %18
%20 = load i32, i32* %3
%21 = srem i32 %20, 10
%22 = add nsw i32 %21, 48
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8 %23, i8* %28
br label %29
29: ; preds = %19
%30 = load i32, i32* %3
%31 = sdiv i32 %30, 10
store i32 %31, i32* %3
%32 = icmp sgt i32 %31, 0
br i1 %32, label %19, label %33
33: ; preds = %29
%34 = load i32, i32* %6
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %33
%37 = load i8*, i8** %4
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
store i8 45, i8* %41
br label %42
42: ; preds = %36, %33
%43 = load i8*, i8** %4
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 0, i8* %46
%47 = load i8*, i8** %4
%48 = call i32 @rever(i8* %47)
ret void
}

LLVM IR (-O2):
@.str = [40 x i8] c"error: the argument of my_atoi is NULL!\00"
define void @my_itoa(i32 %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %2
%8 = icmp slt i32 %0, 0
%9 = sub nsw i32 0, %0
%10 = select i1 %8, i32 %9, i32 %0
br label %11
11: ; preds = %11, %7
%12 = phi i64 [ %17, %11 ], [ 0, %7 ]
%13 = phi i32 [ %19, %11 ], [ %10, %7 ]
%14 = srem i32 %13, 10
%15 = trunc i32 %14 to i8
%16 = add nsw i8 %15, 48
%17 = add nuw i64 %12, 1
%18 = getelementptr inbounds i8, i8* %1, i64 %12
store i8 %16, i8* %18
%19 = sdiv i32 %13, 10
%20 = icmp sgt i32 %13, 9
br i1 %20, label %11, label %21
21: ; preds = %11
br i1 %8, label %22, label %26
22: ; preds = %21
%23 = add i64 %12, 2
%24 = and i64 %17, 4294967295
%25 = getelementptr inbounds i8, i8* %1, i64 %24
store i8 45, i8* %25
br label %26
26: ; preds = %22, %21
%27 = phi i64 [ %23, %22 ], [ %17, %21 ]
%28 = shl i64 %27, 32
%29 = ashr exact i64 %28, 32
%30 = getelementptr inbounds i8, i8* %1, i64 %29
store i8 0, i8* %30
%31 = tail call i32 @rever(i8* %1)
ret void
}