#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*/ clearlog();
int /*<<< orphan*/ free(char *);
char *getlog();
int /*<<< orphan*/ logmsg(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ savelog(char *);
int main(int argc, char **argv) {
  logmsg("hello world");
  logmsg("ls -l");
  logmsg("cp");
  logmsg("mv");
  char *msgs = getlog();
  printf("%s\n", msgs);
  free(msgs);
  savelog("/tmp/log");
  clearlog();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
call   1070 <logmsg@plt>
lea    0xe83(%rip),%rdi
call   1070 <logmsg@plt>
lea    0xe7d(%rip),%rdi
call   1070 <logmsg@plt>
lea    0xe74(%rip),%rdi
call   1070 <logmsg@plt>
mov    $0x0,%al
call   1080 <getlog@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xe4b(%rip),%rdi
call   1050 <savelog@plt>
mov    $0x0,%al
call   1060 <clearlog@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xe98(%rip),%rdi
call   1070 <logmsg@plt>
lea    0xe98(%rip),%rdi
call   1070 <logmsg@plt>
lea    0xe92(%rip),%rdi
call   1070 <logmsg@plt>
lea    0xe89(%rip),%rdi
call   1070 <logmsg@plt>
xor    %eax,%eax
call   1080 <getlog@plt>
mov    %rax,%rbx
lea    0xe76(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe63(%rip),%rdi
call   1050 <savelog@plt>
xor    %eax,%eax
call   1060 <clearlog@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"hello world\00"
@.str.1 = [6 x i8] c"ls -l\00"
@.str.2 = [3 x i8] c"cp\00"
@.str.3 = [3 x i8] c"mv\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [9 x i8] c"/tmp/log\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 @logmsg(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @logmsg(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @logmsg(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @logmsg(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%11 = call i8* (...) @getlog()
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %6
%15 = call i32 @free(i8* %14)
%16 = call i32 @savelog(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%17 = call i32 (...) @clearlog()
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"hello world\00"
@.str.1 = [6 x i8] c"ls -l\00"
@.str.2 = [3 x i8] c"cp\00"
@.str.3 = [3 x i8] c"mv\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [9 x i8] c"/tmp/log\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @logmsg(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @logmsg(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @logmsg(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @logmsg(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i8* (...) @getlog()
%8 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%9 = tail call i32 @free(i8* %7)
%10 = tail call i32 @savelog(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%11 = tail call i32 (...) @clearlog()
ret i32 0
}