#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;
};
typedef int /*<<< orphan*/ int64_t;

/* Variables and functions */
struct string *create_string_copy(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
int snprintf(char *, int, char *, int /*<<< orphan*/);
struct string *_prim_int_str(int64_t p1) {
  char buffer[256];
  int len = snprintf(buffer, 256, "%ld", p1);
  if (len >= 0 && len < 256) {
    return create_string_copy(buffer);
  } else {
    printf("_prim_int_str\n");
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<_prim_int_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x100,%esi
lea    0xe9c(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jl     11a1 <_prim_int_str+0x61>
cmpl   $0x100,-0x114(%rbp)
jge    11a1 <_prim_int_str+0x61>
lea    -0x110(%rbp),%rdi
call   1050 <create_string_copy@plt>
add    $0x120,%rsp
pop    %rbp
ret
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<_prim_int_str>:
sub    $0x108,%rsp
mov    %edi,%ecx
lea    0xeb0(%rip),%rdx
mov    %rsp,%rdi
mov    $0x100,%esi
call   1040 <snprintf@plt>
cmp    $0xff,%eax
ja     1174 <_prim_int_str+0x34>
mov    %rsp,%rdi
call   1050 <create_string_copy@plt>
add    $0x108,%rsp
ret
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.string = type { i32 }
@.str = [4 x i8] c"%ld\00"
@.str.1 = [15 x i8] c"_prim_int_str\0A\00"
define %struct.string* @_prim_int_str(i32 %0) {
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* %2
%7 = call i32 @snprintf(i8* %5, i32 256, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp sge i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %1
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 256
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%15 = call %struct.string* @create_string_copy(i8* %14)
ret %struct.string* %15
16: ; preds = %10, %1
%17 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
}

LLVM IR (-O2):
%struct.string = type { i32 }
@.str = [4 x i8] c"%ld\00"
@str = [14 x i8] c"_prim_int_str\00"
define %struct.string* @_prim_int_str(i32 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @snprintf(i8* %3, i32 256, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = icmp ult i32 %4, 256
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call %struct.string* @create_string_copy(i8* %3)
ret %struct.string* %7
8: ; preds = %1
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%10 = call i32 @exit(i32 -1)
unreachable
}