#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*/ assert(int);
void *ba_alloc(int);
void *ba_free(void *);
void *ba_resize(void *, int);
int ba_size(void *);
int /*<<< orphan*/ stpcpy(void *, char *);
scalar_t__ strcmp(void *, char *);
int strlen(void *);
scalar_t__ strncmp(void *, char *, int);
int main() {
  {
    void *memory = ba_alloc(10);
    stpcpy(memory, "123456789");
    memory = ba_resize(memory, 8);
    assert(strncmp(memory, "12345678", 8) == 0);
    assert(ba_size(memory) == 8);
    memory = ba_free(memory);
  }
  {
    void *memory = ba_alloc(10);
    stpcpy(memory, "123456789");
    memory = ba_resize(memory, 14);
    assert(strcmp(memory, "123456789") == 0);
    assert(strlen(memory) == 9);
    stpcpy(memory + 9, "abcd");
    assert(strcmp(memory, "123456789abcd") == 0);
    assert(strlen(memory) == 13);
    memory = ba_free(memory);
  }
  {
    void *memory = ba_alloc(10);
    stpcpy(memory, "123456789");
    memory = ba_resize(memory, 10);
    assert(strcmp(memory, "123456789") == 0);
    assert(strlen(memory) == 9);
    memory = ba_free(memory);
  }
  {
    void *memory = NULL;
    memory = ba_resize(memory, 10);
    assert(memory != NULL);
    memory = ba_free(memory);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xa,%edi
call   10a0 <ba_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1040 <stpcpy@plt>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   10b0 <ba_resize@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe30(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1090 <ba_size@plt>
cmp    $0x8,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ba_free@plt>
mov    %rax,-0x10(%rbp)
mov    $0xa,%edi
call   10a0 <ba_alloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdcc(%rip),%rsi
call   1040 <stpcpy@plt>
mov    -0x18(%rbp),%rdi
mov    $0xe,%esi
call   10b0 <ba_resize@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdaa(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x9,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rdi
add    $0x9,%rdi
lea    0xd88(%rip),%rsi
call   1040 <stpcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xd6f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0xd,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ba_free@plt>
mov    %rax,-0x18(%rbp)
mov    $0xa,%edi
call   10a0 <ba_alloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xd07(%rip),%rsi
call   1040 <stpcpy@plt>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   10b0 <ba_resize@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xce5(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x9,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ba_free@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0xa,%esi
call   10b0 <ba_resize@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x28(%rbp),%rdi
call   1060 <ba_free@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0xa,%edi
call   10a0 <ba_alloc@plt>
mov    %rax,%rbx
lea    0xe58(%rip),%r14
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <stpcpy@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   10b0 <ba_resize@plt>
mov    %rax,%rbx
lea    0xe40(%rip),%rsi
mov    %rax,%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
call   1090 <ba_size@plt>
xor    %edi,%edi
cmp    $0x8,%eax
sete   %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
call   1060 <ba_free@plt>
mov    $0xa,%edi
call   10a0 <ba_alloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <stpcpy@plt>
mov    %rbx,%rdi
mov    $0xe,%esi
call   10b0 <ba_resize@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
xor    %edi,%edi
cmp    $0x9,%eax
sete   %dil
call   1080 <assert@plt>
lea    0x9(%rbx),%rdi
lea    0xdb7(%rip),%rsi
call   1040 <stpcpy@plt>
lea    0xda2(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
xor    %edi,%edi
cmp    $0xd,%eax
sete   %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
call   1060 <ba_free@plt>
mov    $0xa,%edi
call   10a0 <ba_alloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <stpcpy@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   10b0 <ba_resize@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
xor    %edi,%edi
cmp    $0x9,%eax
sete   %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
call   1060 <ba_free@plt>
xor    %edi,%edi
mov    $0xa,%esi
call   10b0 <ba_resize@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
call   1060 <ba_free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"123456789\00"
@.str.1 = [9 x i8] c"12345678\00"
@.str.2 = [5 x i8] c"abcd\00"
@.str.3 = [14 x i8] c"123456789abcd\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i8* @ba_alloc(i32 10)
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @stpcpy(i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** %2
%10 = call i8* @ba_resize(i8* %9, i32 8)
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%13 = icmp eq i64 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8*, i8** %2
%17 = call i32 @ba_size(i8* %16)
%18 = icmp eq i32 %17, 8
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i8*, i8** %2
%22 = call i8* @ba_free(i8* %21)
store i8* %22, i8** %2
%23 = call i8* @ba_alloc(i32 10)
store i8* %23, i8** %3
%24 = load i8*, i8** %3
%25 = call i32 @stpcpy(i8* %24, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%26 = load i8*, i8** %3
%27 = call i8* @ba_resize(i8* %26, i32 14)
store i8* %27, i8** %3
%28 = load i8*, i8** %3
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = load i8*, i8** %3
%34 = call i32 @strlen(i8* %33)
%35 = icmp eq i32 %34, 9
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load i8*, i8** %3
%39 = getelementptr i8, i8* %38, i64 9
%40 = call i32 @stpcpy(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%41 = load i8*, i8** %3
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i8*, i8** %3
%47 = call i32 @strlen(i8* %46)
%48 = icmp eq i32 %47, 13
%49 = zext i1 %48 to i32
%50 = call i32 @assert(i32 %49)
%51 = load i8*, i8** %3
%52 = call i8* @ba_free(i8* %51)
store i8* %52, i8** %3
%53 = call i8* @ba_alloc(i32 10)
store i8* %53, i8** %4
%54 = load i8*, i8** %4
%55 = call i32 @stpcpy(i8* %54, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%56 = load i8*, i8** %4
%57 = call i8* @ba_resize(i8* %56, i32 10)
store i8* %57, i8** %4
%58 = load i8*, i8** %4
%59 = call i64 @strcmp(i8* %58, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%60 = icmp eq i64 %59, 0
%61 = zext i1 %60 to i32
%62 = call i32 @assert(i32 %61)
%63 = load i8*, i8** %4
%64 = call i32 @strlen(i8* %63)
%65 = icmp eq i32 %64, 9
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
%68 = load i8*, i8** %4
%69 = call i8* @ba_free(i8* %68)
store i8* %69, i8** %4
store i8* null, i8** %5
%70 = load i8*, i8** %5
%71 = call i8* @ba_resize(i8* %70, i32 10)
store i8* %71, i8** %5
%72 = load i8*, i8** %5
%73 = icmp ne i8* %72, null
%74 = zext i1 %73 to i32
%75 = call i32 @assert(i32 %74)
%76 = load i8*, i8** %5
%77 = call i8* @ba_free(i8* %76)
store i8* %77, i8** %5
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"123456789\00"
@.str.1 = [9 x i8] c"12345678\00"
@.str.2 = [5 x i8] c"abcd\00"
@.str.3 = [14 x i8] c"123456789abcd\00"
define i32 @main() {
%1 = tail call i8* @ba_alloc(i32 10)
%2 = tail call i32 @stpcpy(i8* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%3 = tail call i8* @ba_resize(i8* %1, i32 8)
%4 = tail call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%5 = icmp eq i64 %4, 0
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i32 @ba_size(i8* %3)
%9 = icmp eq i32 %8, 8
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = tail call i8* @ba_free(i8* %3)
%13 = tail call i8* @ba_alloc(i32 10)
%14 = tail call i32 @stpcpy(i8* %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%15 = tail call i8* @ba_resize(i8* %13, i32 14)
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
%19 = tail call i32 @assert(i32 %18)
%20 = tail call i32 @strlen(i8* %15)
%21 = icmp eq i32 %20, 9
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
%24 = getelementptr i8, i8* %15, i64 9
%25 = tail call i32 @stpcpy(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%26 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
%28 = zext i1 %27 to i32
%29 = tail call i32 @assert(i32 %28)
%30 = tail call i32 @strlen(i8* %15)
%31 = icmp eq i32 %30, 13
%32 = zext i1 %31 to i32
%33 = tail call i32 @assert(i32 %32)
%34 = tail call i8* @ba_free(i8* %15)
%35 = tail call i8* @ba_alloc(i32 10)
%36 = tail call i32 @stpcpy(i8* %35, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%37 = tail call i8* @ba_resize(i8* %35, i32 10)
%38 = tail call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
%40 = zext i1 %39 to i32
%41 = tail call i32 @assert(i32 %40)
%42 = tail call i32 @strlen(i8* %37)
%43 = icmp eq i32 %42, 9
%44 = zext i1 %43 to i32
%45 = tail call i32 @assert(i32 %44)
%46 = tail call i8* @ba_free(i8* %37)
%47 = tail call i8* @ba_resize(i8* null, i32 10)
%48 = icmp ne i8* %47, null
%49 = zext i1 %48 to i32
%50 = tail call i32 @assert(i32 %49)
%51 = tail call i8* @ba_free(i8* %47)
ret i32 0
}