#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 abs(int);
int /*<<< orphan*/ charstring_byte(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
void charstring_int(int num) {
  int x;
  if (num >= -107 && num <= 107) {
    charstring_byte(num + 139);
  } else if (num >= 108 && num <= 1131) {
    x = num - 108;
    charstring_byte(x / 256 + 247);
    charstring_byte(x % 256);
  } else if (num >= -1131 && num <= -108) {
    x = abs(num) - 108;
    charstring_byte(x / 256 + 251);
    charstring_byte(x % 256);
  } else if (num >= (-2147483647 - 1) && num <= 2147483647) {
    charstring_byte(255);
    charstring_byte(num >> 24);
    charstring_byte(num >> 16);
    charstring_byte(num >> 8);
    charstring_byte(num);
  } else {
    fprintf(stderr, "error: cannot format the integer %d, too large\n", num);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<charstring_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0xffffff95,-0x4(%rbp)
jl     1172 <charstring_int+0x32>
cmpl   $0x6b,-0x4(%rbp)
jg     1172 <charstring_int+0x32>
mov    -0x4(%rbp),%edi
add    $0x8b,%edi
call   1050 <charstring_byte@plt>
jmp    1298 <charstring_int+0x158>
cmpl   $0x6c,-0x4(%rbp)
jl     11c1 <charstring_int+0x81>
cmpl   $0x46b,-0x4(%rbp)
jg     11c1 <charstring_int+0x81>
mov    -0x4(%rbp),%eax
sub    $0x6c,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
add    $0xf7,%edi
call   1050 <charstring_byte@plt>
mov    -0x8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1050 <charstring_byte@plt>
jmp    1293 <charstring_int+0x153>
cmpl   $0xfffffb95,-0x4(%rbp)
jl     1215 <charstring_int+0xd5>
cmpl   $0xffffff94,-0x4(%rbp)
jg     1215 <charstring_int+0xd5>
mov    -0x4(%rbp),%edi
call   1030 <abs@plt>
sub    $0x6c,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
add    $0xfb,%edi
call   1050 <charstring_byte@plt>
mov    -0x8(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1050 <charstring_byte@plt>
jmp    128e <charstring_int+0x14e>
cmpl   $0x80000000,-0x4(%rbp)
jl     1267 <charstring_int+0x127>
cmpl   $0x7fffffff,-0x4(%rbp)
jg     1267 <charstring_int+0x127>
mov    $0xff,%edi
call   1050 <charstring_byte@plt>
mov    -0x4(%rbp),%edi
sar    $0x18,%edi
call   1050 <charstring_byte@plt>
mov    -0x4(%rbp),%edi
sar    $0x10,%edi
call   1050 <charstring_byte@plt>
mov    -0x4(%rbp),%edi
sar    $0x8,%edi
call   1050 <charstring_byte@plt>
mov    -0x4(%rbp),%edi
call   1050 <charstring_byte@plt>
jmp    1289 <charstring_int+0x149>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xd86(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    128e <charstring_int+0x14e>
jmp    1293 <charstring_int+0x153>
jmp    1298 <charstring_int+0x158>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<charstring_int>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x6b(%rbx),%eax
cmp    $0xd6,%eax
ja     1127 <charstring_int+0x17>
add    $0x8b,%ebx
jmp    1191 <charstring_int+0x81>
lea    -0x6c(%rbx),%ebp
cmp    $0x3ff,%ebp
ja     113f <charstring_int+0x2f>
mov    %ebp,%edi
shr    $0x8,%edi
add    $0xf7,%edi
jmp    115e <charstring_int+0x4e>
lea    0x46b(%rbx),%eax
cmp    $0x3ff,%eax
ja     1169 <charstring_int+0x59>
mov    $0xffffff94,%ebp
sub    %ebx,%ebp
mov    %ebp,%edi
shr    $0x8,%edi
add    $0xfb,%edi
call   1030 <charstring_byte@plt>
movzbl %bpl,%ebx
jmp    1191 <charstring_int+0x81>
mov    $0xff,%edi
call   1030 <charstring_byte@plt>
mov    %ebx,%edi
sar    $0x18,%edi
call   1030 <charstring_byte@plt>
mov    %ebx,%edi
sar    $0x10,%edi
call   1030 <charstring_byte@plt>
mov    %ebx,%edi
sar    $0x8,%edi
call   1030 <charstring_byte@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <charstring_byte@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [48 x i8] c"error: cannot format the integer %d, too large\0A\00"
define void @charstring_int(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp sge i32 %4, -107
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = load i32, i32* %2
%8 = icmp sle i32 %7, 107
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i32, i32* %2
%11 = add nsw i32 %10, 139
%12 = call i32 @charstring_byte(i32 %11)
br label %73
13: ; preds = %6, %1
%14 = load i32, i32* %2
%15 = icmp sge i32 %14, 108
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = load i32, i32* %2
%18 = icmp sle i32 %17, 1131
br i1 %18, label %19, label %29
19: ; preds = %16
%20 = load i32, i32* %2
%21 = sub nsw i32 %20, 108
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = sdiv i32 %22, 256
%24 = add nsw i32 %23, 247
%25 = call i32 @charstring_byte(i32 %24)
%26 = load i32, i32* %3
%27 = srem i32 %26, 256
%28 = call i32 @charstring_byte(i32 %27)
br label %72
29: ; preds = %16, %13
%30 = load i32, i32* %2
%31 = icmp sge i32 %30, -1131
br i1 %31, label %32, label %46
32: ; preds = %29
%33 = load i32, i32* %2
%34 = icmp sle i32 %33, -108
br i1 %34, label %35, label %46
35: ; preds = %32
%36 = load i32, i32* %2
%37 = call i32 @abs(i32 %36)
%38 = sub nsw i32 %37, 108
store i32 %38, i32* %3
%39 = load i32, i32* %3
%40 = sdiv i32 %39, 256
%41 = add nsw i32 %40, 251
%42 = call i32 @charstring_byte(i32 %41)
%43 = load i32, i32* %3
%44 = srem i32 %43, 256
%45 = call i32 @charstring_byte(i32 %44)
br label %71
46: ; preds = %32, %29
%47 = load i32, i32* %2
%48 = icmp sge i32 %47, -2147483648
br i1 %48, label %49, label %65
49: ; preds = %46
%50 = load i32, i32* %2
%51 = icmp sle i32 %50, 2147483647
br i1 %51, label %52, label %65
52: ; preds = %49
%53 = call i32 @charstring_byte(i32 255)
%54 = load i32, i32* %2
%55 = ashr i32 %54, 24
%56 = call i32 @charstring_byte(i32 %55)
%57 = load i32, i32* %2
%58 = ashr i32 %57, 16
%59 = call i32 @charstring_byte(i32 %58)
%60 = load i32, i32* %2
%61 = ashr i32 %60, 8
%62 = call i32 @charstring_byte(i32 %61)
%63 = load i32, i32* %2
%64 = call i32 @charstring_byte(i32 %63)
br label %70
65: ; preds = %49, %46
%66 = load i32, i32* @stderr
%67 = load i32, i32* %2
%68 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %67)
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %52
br label %71
71: ; preds = %70, %35
br label %72
72: ; preds = %71, %19
br label %73
73: ; preds = %72, %9
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
define void @charstring_int(i32 %0) {
%2 = add i32 %0, 107
%3 = icmp ult i32 %2, 215
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = add nsw i32 %0, 139
br label %31
6: ; preds = %1
%7 = add i32 %0, -108
%8 = icmp ult i32 %7, 1024
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = lshr i32 %7, 8
%11 = add nuw nsw i32 %10, 247
%12 = tail call i32 @charstring_byte(i32 %11)
%13 = and i32 %7, 255
br label %31
14: ; preds = %6
%15 = add i32 %0, 1131
%16 = icmp ult i32 %15, 1024
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = sub nuw nsw i32 -108, %0
%19 = lshr i32 %18, 8
%20 = add nuw nsw i32 %19, 251
%21 = tail call i32 @charstring_byte(i32 %20)
%22 = and i32 %18, 255
br label %31
23: ; preds = %14
%24 = tail call i32 @charstring_byte(i32 255)
%25 = ashr i32 %0, 24
%26 = tail call i32 @charstring_byte(i32 %25)
%27 = ashr i32 %0, 16
%28 = tail call i32 @charstring_byte(i32 %27)
%29 = ashr i32 %0, 8
%30 = tail call i32 @charstring_byte(i32 %29)
br label %31
31: ; preds = %9, %23, %17, %4
%32 = phi i32 [ %13, %9 ], [ %0, %23 ], [ %22, %17 ], [ %5, %4 ]
%33 = tail call i32 @charstring_byte(i32 %32)
ret void
}