#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 */
scalar_t__ copyfile(char const *, char *);
scalar_t__ fileexists(char *);
int geteuid();
int /*<<< orphan*/ printf(char *, ...);
int system(char *);
int main(int argc, const char *argv[]) {
  char *buf;
  int len;
  int res;
  printf("as %d\n", geteuid());
  if (argc != 4) {
    printf("Usage: f1 f2 f3");
    return -1;
  }
  if (fileexists("/home/root/setup/instance")) {
    printf("Already initialised (/home/root/setup/instance exists)");
    return -2;
  }
  if (copyfile(argv[1], "/home/root/setup/instance") != 0 ||
      copyfile(argv[2], "/etc/nginx/conf/htpasswd") != 0 ||
      copyfile(argv[3], "/etc/nginx/sites-available/default") != 0)
    return -1;
  printf("signal nginx");
  res = system("nginx -s reload");
  printf("signal nginx = %d", res);
  return res;
}


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)
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,%esi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x4,-0x8(%rbp)
je     11a1 <main+0x51>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126b <main+0x11b>
lea    0xe6f(%rip),%rdi
call   1060 <fileexists@plt>
cmp    $0x0,%rax
je     11d1 <main+0x81>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    126b <main+0x11b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe37(%rip),%rsi
call   1070 <copyfile@plt>
cmp    $0x0,%rax
jne    122b <main+0xdb>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe6a(%rip),%rsi
call   1070 <copyfile@plt>
cmp    $0x0,%rax
jne    122b <main+0xdb>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe65(%rip),%rsi
call   1070 <copyfile@plt>
cmp    $0x0,%rax
je     1237 <main+0xe7>
movl   $0xffffffff,-0x4(%rbp)
jmp    126b <main+0x11b>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe65(%rip),%rdi
call   1030 <system@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1050 <geteuid@plt>
lea    0xe9a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x4,%ebp
jne    119a <main+0x4a>
lea    0xe9c(%rip),%rdi
call   1060 <fileexists@plt>
test   %rax,%rax
je     11b6 <main+0x66>
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xfffffffe,%ebp
jmp    11ad <main+0x5d>
lea    0xe66(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x8(%rbx),%rdi
lea    0xe56(%rip),%rsi
call   1070 <copyfile@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    11ad <main+0x5d>
mov    0x10(%rbx),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <copyfile@plt>
test   %rax,%rax
jne    11ad <main+0x5d>
mov    0x18(%rbx),%rdi
lea    0xe91(%rip),%rsi
call   1070 <copyfile@plt>
test   %rax,%rax
jne    11ad <main+0x5d>
lea    0xea3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea2(%rip),%rdi
call   1030 <system@plt>
mov    %eax,%ebp
lea    0xea4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ad <main+0x5d>

LLVM IR (-O0):
@.str = [7 x i8] c"as %d\0A\00"
@.str.1 = [16 x i8] c"Usage: f1 f2 f3\00"
@.str.2 = [26 x i8] c"/home/root/setup/instance\00"
@.str.3 = [55 x i8] c"Already initialised (/home/root/setup/instance exists)\00"
@.str.4 = [25 x i8] c"/etc/nginx/conf/htpasswd\00"
@.str.5 = [35 x i8] c"/etc/nginx/sites-available/default\00"
@.str.6 = [13 x i8] c"signal nginx\00"
@.str.7 = [16 x i8] c"nginx -s reload\00"
@.str.8 = [18 x i8] c"signal nginx = %d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @geteuid()
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 4
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %45
15: ; preds = %2
%16 = call i64 @fileexists(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
store i32 -2, i32* %3
br label %45
20: ; preds = %15
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @copyfile(i8* %23, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %38, label %26
26: ; preds = %20
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i64 @copyfile(i8* %29, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp ne i64 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %26
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 3
%35 = load i8*, i8** %34
%36 = call i64 @copyfile(i8* %35, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %32, %26, %20
store i32 -1, i32* %3
br label %45
39: ; preds = %32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%41 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
store i32 %41, i32* %8
%42 = load i32, i32* %8
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %8
store i32 %44, i32* %3
br label %45
45: ; preds = %39, %38, %18, %13
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [7 x i8] c"as %d\0A\00"
@.str.1 = [16 x i8] c"Usage: f1 f2 f3\00"
@.str.2 = [26 x i8] c"/home/root/setup/instance\00"
@.str.3 = [55 x i8] c"Already initialised (/home/root/setup/instance exists)\00"
@.str.4 = [25 x i8] c"/etc/nginx/conf/htpasswd\00"
@.str.5 = [35 x i8] c"/etc/nginx/sites-available/default\00"
@.str.6 = [13 x i8] c"signal nginx\00"
@.str.7 = [16 x i8] c"nginx -s reload\00"
@.str.8 = [18 x i8] c"signal nginx = %d\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @geteuid()
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %0, 4
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %32
8: ; preds = %2
%9 = tail call i64 @fileexists(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
br label %32
13: ; preds = %8
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i64 @copyfile(i8* %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %32
18: ; preds = %13
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i64 @copyfile(i8* %20, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %18
%24 = getelementptr inbounds i8*, i8** %1, i64 3
%25 = load i8*, i8** %24
%26 = tail call i64 @copyfile(i8* %25, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%30 = tail call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %13, %18, %23, %28, %11, %6
%33 = phi i32 [ -1, %6 ], [ -2, %11 ], [ %30, %28 ], [ -1, %23 ], [ -1, %18 ], [ -1, %13 ]
ret i32 %33
}