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

/* Variables and functions */
int /*<<< orphan*/ send_string(int, char *);
int /*<<< orphan*/ shim_log(char *, int, char *, int);
int snprintf(char *, int, char *, int);
ssize_t send_int(int fd, int value) {
  int size = snprintf(NULL, 0, "%d", value);
  char buffer[size + 1];
  snprintf(buffer, size + 1, "%d", value);
  buffer[size] = 0;
  shim_log("%d (%s) has size %d", value, buffer, size);
  return send_string(fd, buffer);
}


x86 assembly (clang, -O0):
<send_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
lea    0xec9(%rip),%rdx
xor    %esi,%esi
mov    %esi,%edi
call   1040 <snprintf@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x8(%rbp),%ecx
lea    0xe84(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x28(%rbp),%rdx
movslq -0xc(%rbp),%rax
movb   $0x0,(%rdx,%rax,1)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%ecx
lea    0xe55(%rip),%rdi
call   1050 <shim_log@plt>
mov    -0x28(%rbp),%rsi
mov    -0x4(%rbp),%edi
call   1030 <send_string@plt>
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_int>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r12d
mov    %edi,%r14d
lea    0xec6(%rip),%r15
xor    %edi,%edi
xor    %esi,%esi
mov    %r15,%rdx
mov    %r12d,%ecx
call   1040 <snprintf@plt>
mov    %eax,%r13d
lea    0x1(%r13),%esi
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r12d,%ecx
call   1040 <snprintf@plt>
movslq %r13d,%rcx
movb   $0x0,(%rcx,%rbx,1)
lea    0xe72(%rip),%rdi
mov    %r12d,%esi
mov    %rbx,%rdx
call   1050 <shim_log@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1030 <send_string@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [20 x i8] c"%d (%s) has size %d\00"
define i32 @send_int(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = call i32 @snprintf(i8* null, i32 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i8, i64 %12
store i64 %12, i64* %7
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 1
%17 = load i32, i32* %4
%18 = call i32 @snprintf(i8* %14, i32 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %14, i64 %20
store i8 0, i8* %21
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = call i32 @shim_log(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %22, i8* %14, i32 %23)
%25 = load i32, i32* %3
%26 = call i32 @send_string(i32 %25, i8* %14)
%27 = load i8*, i8** %6
ret i32 %26
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [20 x i8] c"%d (%s) has size %d\00"
define i32 @send_int(i32 %0, i32 %1) {
%3 = tail call i32 @snprintf(i8* null, i32 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @snprintf(i8* %6, i32 %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%8 = sext i32 %3 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
store i8 0, i8* %9
%10 = call i32 @shim_log(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8* %6, i32 %3)
%11 = call i32 @send_string(i32 %0, i8* %6)
ret i32 %11
}