#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 /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int snprintf(char *, int, char *, int);
char *update_int_string(char *str, int value, size_t *length) {
  char *ret = (char *)malloc(16);
  int l = snprintf(ret, 16, "%d\n", value);
  if (l > 14) {
    ;
    ret[0] = 0;
    l = 0;
  }
  if (str != NULL) {
    free(str);
  }
  if (length != NULL) {
    *length = l;
  }
  return ret;
}


x86 assembly (clang, -O0):
<update_int_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x10,%esi
lea    0xe9c(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xe,-0x24(%rbp)
jle    1184 <update_int_string+0x54>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1198 <update_int_string+0x68>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x18(%rbp)
je     11ae <update_int_string+0x7e>
movslq -0x24(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_int_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xead(%rip),%rdx
mov    %rax,%rdi
mov    $0x10,%esi
mov    %ebp,%ecx
call   1040 <snprintf@plt>
mov    %eax,%ebp
cmp    $0xf,%eax
jl     116e <update_int_string+0x3e>
movb   $0x0,(%rbx)
xor    %ebp,%ebp
test   %r15,%r15
je     117b <update_int_string+0x4b>
mov    %r15,%rdi
call   1030 <free@plt>
test   %r14,%r14
je     1186 <update_int_string+0x56>
movslq %ebp,%rax
mov    %rax,(%r14)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i8* @update_int_string(i8* %0, i32 %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i64* %2, i64** %6
%9 = call i64 @malloc(i32 16)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = load i32, i32* %5
%13 = call i32 @snprintf(i8* %11, i32 16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp sgt i32 %14, 14
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i8*, i8** %7
%18 = getelementptr inbounds i8, i8* %17, i64 0
store i8 0, i8* %18
store i32 0, i32* %8
br label %19
19: ; preds = %16, %3
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = call i32 @free(i8* %23)
br label %25
25: ; preds = %22, %19
%26 = load i64*, i64** %6
%27 = icmp ne i64* %26, null
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = load i64*, i64** %6
store i64 %30, i64* %31
br label %32
32: ; preds = %28, %25
%33 = load i8*, i8** %7
ret i8* %33
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i8* @update_int_string(i8* %0, i32 %1, i64* writeonly %2) {
%4 = tail call i64 @malloc(i32 16)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @snprintf(i8* %5, i32 16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %1)
%7 = icmp sgt i32 %6, 14
br i1 %7, label %8, label %9
8: ; preds = %3
store i8 0, i8* %5
br label %9
9: ; preds = %8, %3
%10 = phi i32 [ 0, %8 ], [ %6, %3 ]
%11 = icmp eq i8* %0, null
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @free(i8* %0)
br label %14
14: ; preds = %12, %9
%15 = icmp eq i64* %2, null
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = sext i32 %10 to i64
store i64 %17, i64* %2
br label %18
18: ; preds = %16, %14
ret i8* %5
}