#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*/ fclose(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  char command[1024];
  int t;
  if (argc == 1) {
    printf("\nShell Proxy\n");
    printf("-----------\n");
    printf("Usage:\n");
    printf("- CLI:\n");
    printf("shellproxy <cmd> <arg>\n");
    printf("shellproxy <cmd> <arg> > redirect.txt\n");
    printf("- PHP:\n");
    printf("system('shellproxy <cmd> <arg> &');\n");
    printf("system('shellproxy <cmd> <arg> > redirect.txt');\n\n");
  }
  command[0] = 0;
  for (t = 1; t < argc; t++) {
    strcat(command, argv[t]);
    strcat(command, " ");
  }
  fclose(stdin);
  fclose(stdout);
  fclose(stderr);
  system(command);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11cf <main+0x8f>
lea    0xe96(%rip),%rdi
call   1050 <printf@plt>
lea    0xe98(%rip),%rdi
call   1050 <printf@plt>
lea    0xe99(%rip),%rdi
call   1050 <printf@plt>
lea    0xe95(%rip),%rdi
call   1050 <printf@plt>
lea    0xe91(%rip),%rdi
call   1050 <printf@plt>
lea    0xe9d(%rip),%rdi
call   1050 <printf@plt>
lea    0xeb8(%rip),%rdi
call   1050 <printf@plt>
lea    0xeb4(%rip),%rdi
call   1050 <printf@plt>
lea    0xecd(%rip),%rdi
call   1050 <printf@plt>
movb   $0x0,-0x410(%rbp)
movl   $0x1,-0x414(%rbp)
mov    -0x414(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1231 <main+0xf1>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x414(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    11e0 <main+0xa0>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
lea    -0x410(%rbp),%rdi
call   1040 <system@plt>
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
cmp    $0x1,%edi
jne    11c7 <main+0x87>
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
lea    0xea8(%rip),%rdi
call   1030 <puts@plt>
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
lea    0xed5(%rip),%rdi
call   1030 <puts@plt>
movb   $0x0,(%rsp)
jmp    1210 <main+0xd0>
movb   $0x0,(%rsp)
jle    1210 <main+0xd0>
mov    %rsi,%r14
mov    %edi,%r12d
mov    $0x1,%ebx
mov    %rsp,%r13
lea    0xe1e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14,%rbx,8),%rsi
mov    %r13,%rdi
call   1060 <strcat@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11f0 <main+0xb0>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1040 <fclose@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   1040 <fclose@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   1040 <fclose@plt>
mov    %rsp,%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"\0AShell Proxy\0A\00"
@.str.1 = [13 x i8] c"-----------\0A\00"
@.str.2 = [8 x i8] c"Usage:\0A\00"
@.str.3 = [8 x i8] c"- CLI:\0A\00"
@.str.4 = [24 x i8] c"shellproxy <cmd> <arg>\0A\00"
@.str.5 = [39 x i8] c"shellproxy <cmd> <arg> > redirect.txt\0A\00"
@.str.6 = [8 x i8] c"- PHP:\0A\00"
@.str.7 = [37 x i8] c"system('shellproxy <cmd> <arg> &');\0A\00"
@.str.8 = [51 x i8] c"system('shellproxy <cmd> <arg> > redirect.txt');\0A\0A\00"
@.str.9 = [2 x i8] c" \00"
@stdin = global i32 0
@stdout = global i32 0
@stderr = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %20
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%18 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0))
%19 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0))
br label %20
20: ; preds = %10, %2
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
store i8 0, i8* %21
store i32 1, i32* %7
br label %22
22: ; preds = %36, %20
%23 = load i32, i32* %7
%24 = load i32, i32* %4
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %39
26: ; preds = %22
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%28 = load i8**, i8*** %5
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @strcat(i8* %27, i8* %32)
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%35 = call i32 @strcat(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %36
36: ; preds = %26
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %22
39: ; preds = %22
%40 = load i32, i32* @stdin
%41 = call i32 @fclose(i32 %40)
%42 = load i32, i32* @stdout
%43 = call i32 @fclose(i32 %42)
%44 = load i32, i32* @stderr
%45 = call i32 @fclose(i32 %44)
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%47 = call i32 @system(i8* %46)
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str.9 = [2 x i8] c" \00"
@stdin = global i32 0
@stdout = global i32 0
@stderr = global i32 0
@str = [13 x i8] c"\0AShell Proxy\00"
@str.10 = [12 x i8] c"-----------\00"
@str.11 = [7 x i8] c"Usage:\00"
@str.12 = [7 x i8] c"- CLI:\00"
@str.13 = [23 x i8] c"shellproxy <cmd> <arg>\00"
@str.14 = [38 x i8] c"shellproxy <cmd> <arg> > redirect.txt\00"
@str.15 = [7 x i8] c"- PHP:\00"
@str.16 = [36 x i8] c"system('shellproxy <cmd> <arg> &');\00"
@str.17 = [50 x i8] c"system('shellproxy <cmd> <arg> > redirect.txt');\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 1
br i1 %5, label %6, label %16
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.10, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.11, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.12, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.13, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.14, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.15, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.16, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.17, i64 0, i64 0))
store i8 0, i8* %4
br label %28
16: ; preds = %2
store i8 0, i8* %4
%17 = icmp sgt i32 %0, 1
br i1 %17, label %18, label %28
18: ; preds = %16
%19 = zext i32 %0 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 1, %18 ], [ %26, %20 ]
%22 = getelementptr inbounds i8*, i8** %1, i64 %21
%23 = load i8*, i8** %22
%24 = call i32 @strcat(i8* %4, i8* %23)
%25 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%26 = add nuw nsw i64 %21, 1
%27 = icmp eq i64 %26, %19
br i1 %27, label %28, label %20
28: ; preds = %20, %6, %16
%29 = load i32, i32* @stdin
%30 = call i32 @fclose(i32 %29)
%31 = load i32, i32* @stdout
%32 = call i32 @fclose(i32 %31)
%33 = load i32, i32* @stderr
%34 = call i32 @fclose(i32 %33)
%35 = call i32 @system(i8* %4)
ret i32 0
}