#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*/ strcat(char *, char *);
void itostr(char c, int integer, char *the_query) {
  char str[5];
  str[0] = c;
  if ((integer / 100) >= 1) {
    str[1] = '0' + (integer / 100);
    str[2] = '0' + ((integer % 100) / 10);
    str[3] = '0' + (integer % 10);
    str[4] = '\0';
  } else {
    if ((integer / 10) >= 1) {
      str[1] = '0' + (integer / 10);
      str[2] = '0' + (integer % 10);
      str[3] = '\0';
    } else {
      str[1] = '0' + integer;
      str[2] = '\0';
    }
  }
  strcat(the_query, str);
}


x86 assembly (clang, -O0):
<itostr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x1(%rbp),%al
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x1,%eax
jl     1187 <itostr+0x77>
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
add    $0x30,%eax
mov    %al,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%eax
mov    %al,-0x13(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%al
mov    %al,-0x12(%rbp)
movb   $0x0,-0x11(%rbp)
jmp    11da <itostr+0xca>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x1,%eax
jl     11c8 <itostr+0xb8>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%eax
mov    %al,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%al
mov    %al,-0x13(%rbp)
movb   $0x0,-0x12(%rbp)
jmp    11d5 <itostr+0xc5>
mov    -0x8(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x14(%rbp)
movb   $0x0,-0x13(%rbp)
jmp    11da <itostr+0xca>
mov    -0x10(%rbp),%rdi
lea    -0x15(%rbp),%rsi
call   1030 <strcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itostr>:
push   %rax
mov    %dil,0x3(%rsp)
cmp    $0x64,%esi
jl     116e <itostr+0x5e>
mov    %esi,%eax
imul   $0x51eb851f,%rax,%rcx
shr    $0x25,%rcx
lea    0x30(%rcx),%edi
mov    %dil,0x4(%rsp)
imul   $0x64,%ecx,%ecx
mov    %esi,%edi
sub    %ecx,%edi
imul   $0xcd,%edi,%ecx
movzwl %cx,%ecx
shr    $0xb,%ecx
or     $0x30,%cl
mov    %cl,0x5(%rsp)
mov    $0xcccccccd,%ecx
imul   %rax,%rcx
shr    $0x23,%rcx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%eax
sub    %eax,%esi
or     $0x30,%sil
mov    $0x4,%eax
mov    $0x3,%ecx
jmp    11ad <itostr+0x9d>
cmp    $0xa,%esi
jl     119f <itostr+0x8f>
movzbl %sil,%eax
imul   $0xcd,%eax,%eax
shr    $0xb,%eax
lea    0x30(%rax),%ecx
mov    %cl,0x4(%rsp)
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %al,%sil
or     $0x30,%sil
mov    $0x3,%eax
mov    $0x2,%ecx
jmp    11ad <itostr+0x9d>
add    $0x30,%sil
mov    $0x2,%eax
mov    $0x1,%ecx
mov    %sil,0x3(%rsp,%rcx,1)
movb   $0x0,0x3(%rsp,%rax,1)
lea    0x3(%rsp),%rsi
mov    %rdx,%rdi
call   1030 <strcat@plt>
pop    %rax
ret

LLVM IR (-O0):
define void @itostr(i8 signext %0, i32 %1, i8* %2) {
%4 = alloca i8
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [5 x i8]
store i8 %0, i8* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i8, i8* %4
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
store i8 %8, i8* %9
%10 = load i32, i32* %5
%11 = sdiv i32 %10, 100
%12 = icmp sge i32 %11, 1
br i1 %12, label %13, label %31
13: ; preds = %3
%14 = load i32, i32* %5
%15 = sdiv i32 %14, 100
%16 = add nsw i32 48, %15
%17 = trunc i32 %16 to i8
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 1
store i8 %17, i8* %18
%19 = load i32, i32* %5
%20 = srem i32 %19, 100
%21 = sdiv i32 %20, 10
%22 = add nsw i32 48, %21
%23 = trunc i32 %22 to i8
%24 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 2
store i8 %23, i8* %24
%25 = load i32, i32* %5
%26 = srem i32 %25, 10
%27 = add nsw i32 48, %26
%28 = trunc i32 %27 to i8
%29 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 3
store i8 %28, i8* %29
%30 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 4
store i8 0, i8* %30
br label %54
31: ; preds = %3
%32 = load i32, i32* %5
%33 = sdiv i32 %32, 10
%34 = icmp sge i32 %33, 1
br i1 %34, label %35, label %47
35: ; preds = %31
%36 = load i32, i32* %5
%37 = sdiv i32 %36, 10
%38 = add nsw i32 48, %37
%39 = trunc i32 %38 to i8
%40 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 1
store i8 %39, i8* %40
%41 = load i32, i32* %5
%42 = srem i32 %41, 10
%43 = add nsw i32 48, %42
%44 = trunc i32 %43 to i8
%45 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 2
store i8 %44, i8* %45
%46 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 3
store i8 0, i8* %46
br label %53
47: ; preds = %31
%48 = load i32, i32* %5
%49 = add nsw i32 48, %48
%50 = trunc i32 %49 to i8
%51 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 1
store i8 %50, i8* %51
%52 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 2
store i8 0, i8* %52
br label %53
53: ; preds = %47, %35
br label %54
54: ; preds = %53, %13
%55 = load i8*, i8** %6
%56 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%57 = call i32 @strcat(i8* %55, i8* %56)
ret void
}

LLVM IR (-O2):
define void @itostr(i8 signext %0, i32 %1, i8* %2) {
%4 = alloca [5 x i8]
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
store i8 %0, i8* %5
%6 = icmp sgt i32 %1, 99
br i1 %6, label %7, label %20
7: ; preds = %3
%8 = udiv i32 %1, 100
%9 = trunc i32 %8 to i8
%10 = add i8 %9, 48
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 1
store i8 %10, i8* %11
%12 = urem i32 %1, 100
%13 = trunc i32 %12 to i8
%14 = udiv i8 %13, 10
%15 = or i8 %14, 48
%16 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 2
store i8 %15, i8* %16
%17 = urem i32 %1, 10
%18 = trunc i32 %17 to i8
%19 = or i8 %18, 48
br label %31
20: ; preds = %3
%21 = icmp sgt i32 %1, 9
%22 = trunc i32 %1 to i8
br i1 %21, label %23, label %29
23: ; preds = %20
%24 = udiv i8 %22, 10
%25 = add nuw nsw i8 %24, 48
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 1
store i8 %25, i8* %26
%27 = urem i8 %22, 10
%28 = or i8 %27, 48
br label %31
29: ; preds = %20
%30 = add i8 %22, 48
br label %31
31: ; preds = %23, %29, %7
%32 = phi i64 [ 2, %23 ], [ 1, %29 ], [ 3, %7 ]
%33 = phi i8 [ %28, %23 ], [ %30, %29 ], [ %19, %7 ]
%34 = phi i64 [ 3, %23 ], [ 2, %29 ], [ 4, %7 ]
%35 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 %32
store i8 %33, i8* %35
%36 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 %34
store i8 0, i8* %36
%37 = call i32 @strcat(i8* %2, i8* %5)
ret void
}