#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 */
struct string {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
int string_concatb(struct string *, char *, int);
int string_putint(struct string *s, int i) {
  char buf[32];
  int len;
  len = snprintf(buf, 32, "%d", i);
  if (len >= (32 - 1)) {
    (void)fputs("error: increase MAXSTRINGLEN in string_putint\n", stderr);
    exit(1);
  }
  return string_concatb(s, buf, len);
}


x86 assembly (clang, -O0):
<string_putint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x20,%esi
lea    0xe9e(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x1f,-0x34(%rbp)
jl     1193 <string_putint+0x53>
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
lea    0xe7f(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1050 <string_concatb@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_putint>:
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ecx
mov    %rdi,%rbx
lea    0xeaf(%rip),%rdx
mov    %rsp,%rdi
mov    $0x20,%esi
call   1030 <snprintf@plt>
cmp    $0x1f,%eax
jge    1176 <string_putint+0x36>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1050 <string_concatb@plt>
add    $0x20,%rsp
pop    %rbx
ret
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
lea    0xe7d(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.string = type { i32 }
@.str = [3 x i8] c"%d\00"
@.str.1 = [47 x i8] c"error: increase MAXSTRINGLEN in string_putint\0A\00"
@stderr = global i32 0
define i32 @string_putint(%struct.string* %0, i32 %1) {
%3 = alloca %struct.string*
%4 = alloca i32
%5 = alloca [32 x i8]
%6 = alloca i32
store %struct.string* %0, %struct.string** %3
store i32 %1, i32* %4
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%8 = load i32, i32* %4
%9 = call i32 @snprintf(i8* %7, i32 32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp sge i32 %10, 31
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fputs(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load %struct.string*, %struct.string** %3
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%19 = load i32, i32* %6
%20 = call i32 @string_concatb(%struct.string* %17, i8* %18, i32 %19)
ret i32 %20
}

LLVM IR (-O2):
%struct.string = type { i32 }
@.str = [3 x i8] c"%d\00"
@.str.1 = [47 x i8] c"error: increase MAXSTRINGLEN in string_putint\0A\00"
@stderr = global i32 0
define i32 @string_putint(%struct.string* %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%6 = icmp sgt i32 %5, 30
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = call i32 @fputs(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = call i32 @string_concatb(%struct.string* %0, i8* %4, i32 %5)
ret i32 %12
}