#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 errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
char *int_to_str(int x) {
  char *s = malloc(sizeof(int) * 8 + 1);
  if (!s) {
    fprintf(stderr, "rbfc: fatal error: %s: Error code %d\n\r", "malloc",
            errno);
    fflush(stderr);
    exit(errno);
  };
  sprintf(s, "%d", x);
  return s;
}


x86 assembly (clang, -O0):
<int_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x21,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b5 <int_to_str+0x65>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
mov    0x2e54(%rip),%rax
mov    (%rax),%ecx
lea    0xe73(%rip),%rsi
lea    0xe93(%rip),%rdx
call   1030 <fprintf@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe6b(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_to_str>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x21,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1182 <int_to_str+0x32>
mov    %rax,%rbx
lea    0xec0(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e57(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e46(%rip),%rbp
mov    0x0(%rbp),%ecx
lea    0xe64(%rip),%rsi
lea    0xe84(%rip),%rdx
call   1030 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    0x0(%rbp),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"rbfc: fatal error: %s: Error code %d\0A\0D\00"
@.str.1 = [7 x i8] c"malloc\00"
@errno = global i32 0
@.str.2 = [3 x i8] c"%d\00"
define i8* @int_to_str(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = call i8* @malloc(i32 33)
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %15, label %7
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @stderr
%12 = call i32 @fflush(i32 %11)
%13 = load i32, i32* @errno
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = load i32, i32* %2
%18 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i8*, i8** %3
ret i8* %19
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"rbfc: fatal error: %s: Error code %d\0A\0D\00"
@.str.1 = [7 x i8] c"malloc\00"
@errno = global i32 0
@.str.2 = [3 x i8] c"%d\00"
define noalias i8* @int_to_str(i32 %0) {
%2 = tail call dereferenceable_or_null(33) i8* @malloc(i32 33)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = load i32, i32* @errno
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @stderr
%9 = tail call i32 @fflush(i32 %8)
%10 = load i32, i32* @errno
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
%13 = tail call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %0)
ret i8* %2
}