#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(char *);
scalar_t__ realloc(char *, int);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int handle_carry(int carry, char **out_string_ptr) {
  int out_len = strlen(*out_string_ptr);
  char *tmp = (char *)calloc(out_len + 1, sizeof(char));
  strncpy(tmp, *out_string_ptr, out_len);
  *out_string_ptr = (char *)realloc(*out_string_ptr, out_len + 2);
  *(*out_string_ptr) = carry + '0';
  *(*out_string_ptr + 1) = 0;
  strncat(*out_string_ptr, tmp, strlen(tmp));
  free(tmp);
  return 0;
}


x86 assembly (clang, -O0):
<handle_carry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x14(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%esi
add    $0x2,%esi
call   1080 <realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x4(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1060 <strncat@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_carry>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r15d
mov    (%rsi),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
lea    0x1(%rbp),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r14
mov    (%rbx),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1040 <strncpy@plt>
mov    (%rbx),%rdi
add    $0x2,%ebp
mov    %ebp,%esi
call   1080 <realloc@plt>
mov    %rax,(%rbx)
add    $0x30,%r15b
mov    %r15b,(%rax)
mov    (%rbx),%rax
movb   $0x0,0x1(%rax)
mov    (%rbx),%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <strncat@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @handle_carry(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i8**, i8*** %4
%8 = load i8*, i8** %7
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = add nsw i32 %10, 1
%12 = call i64 @calloc(i32 %11, i32 1)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = load i8**, i8*** %4
%16 = load i8*, i8** %15
%17 = load i32, i32* %5
%18 = call i32 @strncpy(i8* %14, i8* %16, i32 %17)
%19 = load i8**, i8*** %4
%20 = load i8*, i8** %19
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 2
%23 = call i64 @realloc(i8* %20, i32 %22)
%24 = inttoptr i64 %23 to i8*
%25 = load i8**, i8*** %4
store i8* %24, i8** %25
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 48
%28 = trunc i32 %27 to i8
%29 = load i8**, i8*** %4
%30 = load i8*, i8** %29
store i8 %28, i8* %30
%31 = load i8**, i8*** %4
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8, i8* %32, i64 1
store i8 0, i8* %33
%34 = load i8**, i8*** %4
%35 = load i8*, i8** %34
%36 = load i8*, i8** %6
%37 = load i8*, i8** %6
%38 = call i32 @strlen(i8* %37)
%39 = call i32 @strncat(i8* %35, i8* %36, i32 %38)
%40 = load i8*, i8** %6
%41 = call i32 @free(i8* %40)
ret i32 0
}

LLVM IR (-O2):
define i32 @handle_carry(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 @strlen(i8* %3)
%5 = add nsw i32 %4, 1
%6 = tail call i64 @calloc(i32 %5, i32 1)
%7 = inttoptr i64 %6 to i8*
%8 = load i8*, i8** %1
%9 = tail call i32 @strncpy(i8* %7, i8* %8, i32 %4)
%10 = load i8*, i8** %1
%11 = add nsw i32 %4, 2
%12 = tail call i64 @realloc(i8* %10, i32 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %1
%14 = trunc i32 %0 to i8
%15 = add i8 %14, 48
store i8 %15, i8* %13
%16 = load i8*, i8** %1
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 0, i8* %17
%18 = load i8*, i8** %1
%19 = tail call i32 @strlen(i8* %7)
%20 = tail call i32 @strncat(i8* %18, i8* %7, i32 %19)
%21 = tail call i32 @free(i8* %7)
ret i32 0
}