#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*/ sprintf(char *, char *, int, ...);
int /*<<< orphan*/ strcpy(char *, char *);
void itoshort_a(char *string, int i) {
  int itmp, exp;
  if (i == 0) {
    strcpy(string, "0");
    return;
  }
  if (i < 0) {
    *string++ = 'n';
    i = -i;
  }
  exp = 0;
  itmp = i;
  while (i % 10 == 0) {
    i /= 10;
    exp++;
  }
  if (exp >= 3)
    sprintf(string, "%de%d", i, exp);
  else
    sprintf(string, "%d", itmp);
  return;
}


x86 assembly (clang, -O0):
<itoshort_a>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    114e <itoshort_a+0x2e>
mov    -0x8(%rbp),%rdi
lea    0xebc(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11f0 <itoshort_a+0xd0>
cmpl   $0x0,-0xc(%rbp)
jge    1172 <itoshort_a+0x52>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x6e,(%rax)
xor    %eax,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11af <itoshort_a+0x8f>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117f <itoshort_a+0x5f>
cmpl   $0x3,-0x14(%rbp)
jl     11d6 <itoshort_a+0xb6>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    11eb <itoshort_a+0xcb>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    11f0 <itoshort_a+0xd0>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoshort_a>:
test   %esi,%esi
je     11a6 <itoshort_a+0x86>
mov    %esi,%eax
jns    1135 <itoshort_a+0x15>
movb   $0x6e,(%rdi)
add    $0x1,%rdi
neg    %eax
imul   $0xcccccccd,%eax,%ecx
ror    %ecx
cmp    $0x19999999,%ecx
ja     1196 <itoshort_a+0x76>
mov    $0xffffffff,%ecx
mov    %eax,%edx
nopl   0x0(%rax)
movslq %edx,%rdx
imul   $0x66666667,%rdx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rdx
add    %esi,%edx
imul   $0xcccccccd,%edx,%esi
add    $0x19999998,%esi
ror    %esi
add    $0x1,%ecx
cmp    $0x19999999,%esi
jb     1150 <itoshort_a+0x30>
cmp    $0x2,%ecx
jb     1196 <itoshort_a+0x76>
add    $0x1,%ecx
lea    0xe73(%rip),%rsi
xor    %eax,%eax
jmp    1040 <sprintf@plt>
lea    0xe68(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
jmp    1040 <sprintf@plt>
lea    0xe53(%rip),%rsi
jmp    1030 <strcpy@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
@.str.1 = [6 x i8] c"%de%d\00"
@.str.2 = [3 x i8] c"%d\00"
define void @itoshort_a(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %29
6: ; preds = %2
%7 = icmp slt i32 %1, 0
br i1 %7, label %8, label %11
8: ; preds = %6
%9 = getelementptr inbounds i8, i8* %0, i64 1
store i8 110, i8* %0
%10 = sub nsw i32 0, %1
br label %11
11: ; preds = %8, %6
%12 = phi i32 [ %10, %8 ], [ %1, %6 ]
%13 = phi i8* [ %9, %8 ], [ %0, %6 ]
%14 = urem i32 %12, 10
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %11, %16
%17 = phi i32 [ %20, %16 ], [ 0, %11 ]
%18 = phi i32 [ %19, %16 ], [ %12, %11 ]
%19 = sdiv i32 %18, 10
%20 = add nuw nsw i32 %17, 1
%21 = srem i32 %19, 10
%22 = icmp eq i32 %21, 0
br i1 %22, label %16, label %23
23: ; preds = %16
%24 = icmp ugt i32 %17, 1
br i1 %24, label %25, label %27
25: ; preds = %23
%26 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %20)
br label %29
27: ; preds = %11, %23
%28 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %29
29: ; preds = %25, %27, %4
ret void
}