#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 *);
char *scvector(int /*<<< orphan*/, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
void lengthen_string(char **cur_string, int *len_in, int n_to_add) {
  char *new_string;
  int len;
  len = *len_in;
  new_string = scvector(0, len + n_to_add);
  strncpy(new_string, *cur_string, len);
  if (len > 0)
    free(*cur_string);
  *len_in = len + n_to_add;
  *cur_string = new_string;
}


x86 assembly (clang, -O0):
<lengthen_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
add    -0x14(%rbp),%esi
xor    %edi,%edi
call   1050 <scvector@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x24(%rbp),%edx
call   1040 <strncpy@plt>
cmpl   $0x0,-0x24(%rbp)
jle    1186 <lengthen_string+0x56>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%ecx
add    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lengthen_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rsi),%ebp
add    %ebp,%ebx
xor    %edi,%edi
mov    %ebx,%esi
call   1050 <scvector@plt>
mov    %rax,%r12
mov    (%r14),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1040 <strncpy@plt>
test   %ebp,%ebp
jle    1169 <lengthen_string+0x39>
mov    (%r14),%rdi
call   1030 <free@plt>
mov    %ebx,(%r15)
mov    %r12,(%r14)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @lengthen_string(i8** %0, i32* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8** %0, i8*** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%9 = load i32*, i32** %5
%10 = load i32, i32* %9
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = load i32, i32* %6
%13 = add nsw i32 %11, %12
%14 = call i8* @scvector(i32 0, i32 %13)
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = load i8**, i8*** %4
%17 = load i8*, i8** %16
%18 = load i32, i32* %8
%19 = call i32 @strncpy(i8* %15, i8* %17, i32 %18)
%20 = load i32, i32* %8
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %3
%23 = load i8**, i8*** %4
%24 = load i8*, i8** %23
%25 = call i32 @free(i8* %24)
br label %26
26: ; preds = %22, %3
%27 = load i32, i32* %8
%28 = load i32, i32* %6
%29 = add nsw i32 %27, %28
%30 = load i32*, i32** %5
store i32 %29, i32* %30
%31 = load i8*, i8** %7
%32 = load i8**, i8*** %4
store i8* %31, i8** %32
ret void
}

LLVM IR (-O2):
define void @lengthen_string(i8** nocapture %0, i32* nocapture %1, i32 %2) {
%4 = load i32, i32* %1
%5 = add nsw i32 %4, %2
%6 = tail call i8* @scvector(i32 0, i32 %5)
%7 = load i8*, i8** %0
%8 = tail call i32 @strncpy(i8* %6, i8* %7, i32 %4)
%9 = icmp sgt i32 %4, 0
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i8*, i8** %0
%12 = tail call i32 @free(i8* %11)
br label %13
13: ; preds = %10, %3
store i32 %5, i32* %1
store i8* %6, i8** %0
ret void
}