#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 */
char *blkalloc(scalar_t__);
int /*<<< orphan*/ blkfree(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
void basic_test() {
  char *name = blkalloc((strlen("Austin Shafer") + 1));
  strcpy(name, "Austin Shafer");
  printf("My allocated name is %s\n", name);
  blkfree((name));
  printf("allocated name is now freed\n");
  char *second_name = blkalloc((strlen("Kelby Beam") + 1));
  strcpy(second_name, "Kelby Beam");
  printf("My second allocated name is %s\n", second_name);
  blkfree((second_name));
  printf("second allocated name is now freed\n");
}


x86 assembly (clang, -O0):
<basic_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <blkalloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rsi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1070 <blkfree@plt>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe73(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <blkalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rsi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <blkfree@plt>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basic_test>:
push   %rbx
mov    $0xe,%edi
call   1060 <blkalloc@plt>
mov    %rax,%rbx
lea    0xe9b(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
lea    0xe9a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <blkfree@plt>
lea    0xecc(%rip),%rdi
call   1040 <puts@plt>
mov    $0xb,%edi
call   1060 <blkalloc@plt>
mov    %rax,%rbx
lea    0xe81(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
lea    0xe7d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <blkfree@plt>
lea    0xe84(%rip),%rdi
pop    %rbx
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"Austin Shafer\00"
@.str.1 = [25 x i8] c"My allocated name is %s\0A\00"
@.str.2 = [29 x i8] c"allocated name is now freed\0A\00"
@.str.3 = [11 x i8] c"Kelby Beam\00"
@.str.4 = [32 x i8] c"My second allocated name is %s\0A\00"
@.str.5 = [36 x i8] c"second allocated name is now freed\0A\00"
define void @basic_test() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i64 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = add nsw i64 %3, 1
%5 = call i8* @blkalloc(i64 %4)
store i8* %5, i8** %1
%6 = load i8*, i8** %1
%7 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %1
%11 = call i32 @blkfree(i8* %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%13 = call i64 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%14 = add nsw i64 %13, 1
%15 = call i8* @blkalloc(i64 %14)
store i8* %15, i8** %2
%16 = load i8*, i8** %2
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%18 = load i8*, i8** %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %2
%21 = call i32 @blkfree(i8* %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"Austin Shafer\00"
@.str.1 = [25 x i8] c"My allocated name is %s\0A\00"
@.str.3 = [11 x i8] c"Kelby Beam\00"
@.str.4 = [32 x i8] c"My second allocated name is %s\0A\00"
@str = [28 x i8] c"allocated name is now freed\00"
@str.6 = [35 x i8] c"second allocated name is now freed\00"
define void @basic_test() {
%1 = tail call i8* @blkalloc(i64 14)
%2 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%4 = tail call i32 @blkfree(i8* %1)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%6 = tail call i8* @blkalloc(i64 11)
%7 = tail call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%9 = tail call i32 @blkfree(i8* %6)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.6, i64 0, i64 0))
ret void
}