#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*/ MS_MGC_VAL;
int /*<<< orphan*/ get_path(char *, char *);
char *getenv(char *);
char *malloc(int);
int mount(char *, char *, char *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int overlay(char *command) {
  char *dirname, *homedir, *ovl_arg, *ovl_path, *lowerdir, *upperdir, *workdir;
  dirname = malloc(1024 * sizeof(char));
  homedir = malloc(1024 * sizeof(char));
  ovl_arg = malloc(1024 * sizeof(char));
  ovl_path = malloc(1024 * sizeof(char));
  lowerdir = malloc(1024 * sizeof(char));
  upperdir = malloc(1024 * sizeof(char));
  workdir = malloc(1024 * sizeof(char));
  get_path(dirname, command);
  strcpy(homedir, getenv("HOME"));
  strcpy(lowerdir, "lowerdir=/home,upperdir=");
  strcpy(upperdir, homedir);
  strcat(upperdir, "/.local/share/secapp/");
  strcpy(ovl_path, upperdir);
  strcat(upperdir, dirname);
  strcat(upperdir, "/home,workdir=");
  strcpy(workdir, homedir);
  strcat(workdir, "/.local/share/secapp/wdir");
  strcat(ovl_arg, lowerdir);
  strcat(ovl_arg, upperdir);
  strcat(ovl_arg, workdir);
  strcat(ovl_path, dirname);
  strcat(ovl_path, "/home");
  return mount("overlay", ovl_path, "overlay", MS_MGC_VAL, ovl_arg);
}


x86 assembly (clang, -O0):
<overlay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <get_path@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    0xe16(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x38(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x40(%rbp),%rdi
lea    0xdd9(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    0xdaf(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x28(%rbp),%rsi
mov    0x2d22(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%r8
lea    0xd98(%rip),%rdx
mov    %rdx,%rdi
call   1050 <mount@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<overlay>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x8(%rsp)
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %r13,%rdi
mov    0x8(%rsp),%rsi
call   1070 <get_path@plt>
lea    0xe1c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    0xe0a(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xe09(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strcat@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1080 <strcat@plt>
lea    0xdfa(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strcat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xdef(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcat@plt>
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1080 <strcat@plt>
lea    0xdc9(%rip),%rsi
mov    %r12,%rdi
call   1080 <strcat@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%ecx
lea    0xdb7(%rip),%rdi
mov    %r12,%rsi
mov    %rdi,%rdx
mov    %rbx,%r8
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <mount@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [25 x i8] c"lowerdir=/home,upperdir=\00"
@.str.2 = [22 x i8] c"/.local/share/secapp/\00"
@.str.3 = [15 x i8] c"/home,workdir=\00"
@.str.4 = [26 x i8] c"/.local/share/secapp/wdir\00"
@.str.5 = [6 x i8] c"/home\00"
@.str.6 = [8 x i8] c"overlay\00"
@MS_MGC_VAL = global i32 0
define i32 @overlay(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %2
%10 = call i8* @malloc(i32 1024)
store i8* %10, i8** %3
%11 = call i8* @malloc(i32 1024)
store i8* %11, i8** %4
%12 = call i8* @malloc(i32 1024)
store i8* %12, i8** %5
%13 = call i8* @malloc(i32 1024)
store i8* %13, i8** %6
%14 = call i8* @malloc(i32 1024)
store i8* %14, i8** %7
%15 = call i8* @malloc(i32 1024)
store i8* %15, i8** %8
%16 = call i8* @malloc(i32 1024)
store i8* %16, i8** %9
%17 = load i8*, i8** %3
%18 = load i8*, i8** %2
%19 = call i32 @get_path(i8* %17, i8* %18)
%20 = load i8*, i8** %4
%21 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @strcpy(i8* %20, i8* %21)
%23 = load i8*, i8** %7
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%25 = load i8*, i8** %8
%26 = load i8*, i8** %4
%27 = call i32 @strcpy(i8* %25, i8* %26)
%28 = load i8*, i8** %8
%29 = call i32 @strcat(i8* %28, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%30 = load i8*, i8** %6
%31 = load i8*, i8** %8
%32 = call i32 @strcpy(i8* %30, i8* %31)
%33 = load i8*, i8** %8
%34 = load i8*, i8** %3
%35 = call i32 @strcat(i8* %33, i8* %34)
%36 = load i8*, i8** %8
%37 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%38 = load i8*, i8** %9
%39 = load i8*, i8** %4
%40 = call i32 @strcpy(i8* %38, i8* %39)
%41 = load i8*, i8** %9
%42 = call i32 @strcat(i8* %41, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%43 = load i8*, i8** %5
%44 = load i8*, i8** %7
%45 = call i32 @strcat(i8* %43, i8* %44)
%46 = load i8*, i8** %5
%47 = load i8*, i8** %8
%48 = call i32 @strcat(i8* %46, i8* %47)
%49 = load i8*, i8** %5
%50 = load i8*, i8** %9
%51 = call i32 @strcat(i8* %49, i8* %50)
%52 = load i8*, i8** %6
%53 = load i8*, i8** %3
%54 = call i32 @strcat(i8* %52, i8* %53)
%55 = load i8*, i8** %6
%56 = call i32 @strcat(i8* %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%57 = load i8*, i8** %6
%58 = load i32, i32* @MS_MGC_VAL
%59 = load i8*, i8** %5
%60 = call i32 @mount(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %57, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %58, i8* %59)
ret i32 %60
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [25 x i8] c"lowerdir=/home,upperdir=\00"
@.str.2 = [22 x i8] c"/.local/share/secapp/\00"
@.str.3 = [15 x i8] c"/home,workdir=\00"
@.str.4 = [26 x i8] c"/.local/share/secapp/wdir\00"
@.str.5 = [6 x i8] c"/home\00"
@.str.6 = [8 x i8] c"overlay\00"
@MS_MGC_VAL = global i32 0
define i32 @overlay(i8* %0) {
%2 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%3 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%4 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%5 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%6 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%7 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%8 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%9 = tail call i32 @get_path(i8* %2, i8* %0)
%10 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @strcpy(i8* %3, i8* %10)
%12 = tail call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @strcpy(i8* %7, i8* %3)
%14 = tail call i32 @strcat(i8* %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @strcpy(i8* %5, i8* %7)
%16 = tail call i32 @strcat(i8* %7, i8* %2)
%17 = tail call i32 @strcat(i8* %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%18 = tail call i32 @strcpy(i8* %8, i8* %3)
%19 = tail call i32 @strcat(i8* %8, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%20 = tail call i32 @strcat(i8* %4, i8* %6)
%21 = tail call i32 @strcat(i8* %4, i8* %7)
%22 = tail call i32 @strcat(i8* %4, i8* %8)
%23 = tail call i32 @strcat(i8* %5, i8* %2)
%24 = tail call i32 @strcat(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%25 = load i32, i32* @MS_MGC_VAL
%26 = tail call i32 @mount(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %25, i8* %4)
ret i32 %26
}