#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 */
size_t _clog_append_str(char **, char *, char *, size_t);
int snprintf(char *, int, char *, long);
size_t _clog_append_int(char **dst, char *orig_buf, long int d,
                        size_t cur_size) {
  char buf[40];
  if (snprintf(buf, 40, "%ld", d) >= 40) {
    return cur_size;
  }
  return _clog_append_str(dst, orig_buf, buf, cur_size);
}


x86 assembly (clang, -O0):
<_clog_append_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x28,%esi
lea    0xeb4(%rip),%rdx
call   1040 <snprintf@plt>
cmp    $0x28,%eax
jl     1167 <_clog_append_int+0x47>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1180 <_clog_append_int+0x60>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x50(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1030 <_clog_append_str@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_clog_append_int>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rcx,%rbx
mov    %rdx,%rcx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xec4(%rip),%rdx
mov    %rsp,%rdi
mov    $0x28,%esi
call   1040 <snprintf@plt>
cmp    $0x27,%eax
jg     1162 <_clog_append_int+0x42>
mov    %rsp,%rdx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rcx
call   1030 <_clog_append_str@plt>
mov    %rax,%rbx
mov    %rbx,%rax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
define i64 @_clog_append_int(i8** %0, i8* %1, i64 %2, i64 %3) {
%5 = alloca i64
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca [40 x i8]
store i8** %0, i8*** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i64 %3, i64* %9
%11 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%12 = load i64, i64* %8
%13 = call i32 @snprintf(i8* %11, i32 40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %12)
%14 = icmp sge i32 %13, 40
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = load i64, i64* %9
store i64 %16, i64* %5
br label %23
17: ; preds = %4
%18 = load i8**, i8*** %6
%19 = load i8*, i8** %7
%20 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%21 = load i64, i64* %9
%22 = call i64 @_clog_append_str(i8** %18, i8* %19, i8* %20, i64 %21)
store i64 %22, i64* %5
br label %23
23: ; preds = %17, %15
%24 = load i64, i64* %5
ret i64 %24
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
define i64 @_clog_append_int(i8** %0, i8* %1, i64 %2, i64 %3) {
%5 = alloca [40 x i8]
%6 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%7 = call i32 @snprintf(i8* %6, i32 40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %2)
%8 = icmp sgt i32 %7, 39
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = call i64 @_clog_append_str(i8** %0, i8* %1, i8* %6, i64 %3)
br label %11
11: ; preds = %4, %9
%12 = phi i64 [ %10, %9 ], [ %3, %4 ]
ret i64 %12
}