#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 */
typedef int /*<<< orphan*/ pid_t;
typedef int /*<<< orphan*/ p;
typedef int /*<<< orphan*/ f;
typedef int /*<<< orphan*/ e;

/* Variables and functions */
int /*<<< orphan*/ fork();
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ system(char *);
int main() {
  pid_t pid = fork();
  char *e = malloc(sizeof(e));
  char *p = malloc(sizeof(p));
  e = "./d.sh";
  p = "AAAA";
  char *f = malloc(sizeof(f) * 2);
  sprintf(f, "%s %s", e, p);
  system(f);
  printf("Youpee!\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x4(%rbp)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe7b(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe77(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe57(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <system@plt>
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xea0(%rip),%rsi
lea    0xe8d(%rip),%rdx
lea    0xe8d(%rip),%rcx
mov    %rax,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"./d.sh\00"
@.str.1 = [5 x i8] c"AAAA\00"
@.str.2 = [6 x i8] c"%s %s\00"
@.str.3 = [9 x i8] c"Youpee!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = call i32 (...) @fork()
store i32 %5, i32* %1
%6 = call i8* @malloc(i32 8)
store i8* %6, i8** %2
%7 = call i8* @malloc(i32 8)
store i8* %7, i8** %3
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %3
%8 = call i8* @malloc(i32 16)
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = load i8*, i8** %2
%11 = load i8*, i8** %3
%12 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %10, i8* %11)
%13 = load i8*, i8** %4
%14 = call i32 @system(i8* %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"./d.sh\00"
@.str.1 = [5 x i8] c"AAAA\00"
@.str.2 = [6 x i8] c"%s %s\00"
@str = [8 x i8] c"Youpee!\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%3 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @system(i8* %2)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
ret i32 0
}