#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 *getString();
int /*<<< orphan*/ getStringCallByRef(char *);
char *getStringNoMalloc();
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  char *a = getString();
  printf("MALLOC ### a = %s \n", a);
  free(a);
  char *b = getStringNoMalloc();
  printf("NO MALLOC ### b = %s \n", b);
  char c[100];
  getStringCallByRef(c);
  printf("CALLBYREF ### c = %s \n", c);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getString@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe81(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    $0x0,%al
call   1060 <getStringNoMalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1050 <printf@plt>
lea    -0x90(%rbp),%rdi
call   1070 <getStringCallByRef@plt>
lea    -0x90(%rbp),%rsi
lea    0xe69(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
xor    %eax,%eax
call   1030 <getString@plt>
mov    %rax,%rbx
lea    0xe9a(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
xor    %eax,%eax
call   1060 <getStringNoMalloc@plt>
lea    0xe90(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <getStringCallByRef@plt>
lea    0xe8d(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"MALLOC ### a = %s \0A\00"
@.str.1 = [23 x i8] c"NO MALLOC ### b = %s \0A\00"
@.str.2 = [23 x i8] c"CALLBYREF ### c = %s \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i8* (...) @getString()
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %6
%13 = call i32 @free(i8* %12)
%14 = call i8* (...) @getStringNoMalloc()
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%18 = call i32 @getStringCallByRef(i8* %17)
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %19)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"MALLOC ### a = %s \0A\00"
@.str.1 = [23 x i8] c"NO MALLOC ### b = %s \0A\00"
@.str.2 = [23 x i8] c"CALLBYREF ### c = %s \0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i8]
%4 = tail call i8* (...) @getString()
%5 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = tail call i32 @free(i8* %4)
%7 = tail call i8* (...) @getStringNoMalloc()
%8 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%10 = call i32 @getStringCallByRef(i8* %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %9)
ret i32 0
}