#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int getOwnBytes(char **, char *);
int infectDirectory(char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
char **walkDir(char *);
int main(int argc, char **argv) {
  argc = argc;
  printf("Beginning Infection Integration Test...\n\n");
  printf("Infecting directory ("
         "./infection_test"
         "):\n");
  int infection_status = infectDirectory("./infection_test", argv[0]);
  printf("Status: %s\n", infection_status ? "OK" : "Failed");
  printf("\n");
  printf("Reading own bytes\n");
  char *own_bytes;
  int own_bytes_length = getOwnBytes(&own_bytes, argv[0]);
  printf("Byte length:%d\n", own_bytes_length);
  printf("\n");
  char **ls = walkDir("./infection_test");
  printf("Comparing...\n");
  FILE *fp;
  char *fp_bytes = (char *)malloc(own_bytes_length);
  for (int i = 0; (ls[i])[0] != '\0'; i++) {
    fp = fopen(ls[i], "rb");
    fread(fp_bytes, 1, own_bytes_length, fp);
    printf("Checking %s...", ls[i]);
    for (int j = 0; j < own_bytes_length; j++) {
      if (fp_bytes[j] != own_bytes[j]) {
        printf("failed(%c!=%c) - ", fp_bytes[j], own_bytes[j]);
        printf("@ %d", j);
        break;
      }
    }
    printf("\n");
  }
  free(fp_bytes);
  free(own_bytes);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe8d(%rip),%rdi
call   1080 <infectDirectory@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
lea    0xe9b(%rip),%rsi
lea    0xe91(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    -0x20(%rbp),%rdi
call   1040 <getOwnBytes@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe0a(%rip),%rdi
call   1050 <walkDir@plt>
mov    %rax,-0x30(%rbp)
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x24(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1374 <main+0x1f4>
mov    -0x30(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe0d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fread@plt>
mov    -0x30(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1358 <main+0x1d8>
mov    -0x40(%rbp),%rax
movslq -0x48(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x20(%rbp),%rcx
movslq -0x48(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     1345 <main+0x1c5>
mov    -0x40(%rbp),%rax
movslq -0x48(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
mov    -0x20(%rbp),%rax
movslq -0x48(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x48(%rbp),%esi
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1358 <main+0x1d8>
jmp    134a <main+0x1ca>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    12dd <main+0x15d>
lea    0xcc9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1273 <main+0xf3>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    0xc9b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
lea    0xeab(%rip),%rdi
call   1070 <puts@plt>
lea    0xec8(%rip),%rdi
call   1070 <puts@plt>
mov    0x0(%rbp),%rsi
lea    0xe2f(%rip),%rbx
mov    %rbx,%rdi
call   10a0 <infectDirectory@plt>
test   %eax,%eax
lea    0xe3e(%rip),%rax
lea    0xe34(%rip),%rsi
cmove  %rax,%rsi
lea    0xe1d(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xea5(%rip),%rdi
call   1070 <puts@plt>
mov    0x0(%rbp),%rsi
mov    %rsp,%rdi
call   1050 <getOwnBytes@plt>
mov    %eax,%r14d
lea    0xe00(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
call   1060 <walkDir@plt>
mov    %rax,%rbx
lea    0xe77(%rip),%rdi
call   1070 <puts@plt>
mov    %r14d,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbp
mov    (%rbx),%rdi
cmpb   $0x0,(%rdi)
je     130f <main+0x16f>
mov    %r14d,%r15d
xor    %r12d,%r12d
jmp    12a7 <main+0x107>
lea    0xdd2(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xdd6(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0x8(%rbx,%r12,8),%rdi
add    $0x1,%r12
cmpb   $0x0,(%rdi)
je     130f <main+0x16f>
lea    0xd89(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   1080 <fread@plt>
mov    (%rbx,%r12,8),%rsi
lea    0xd69(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
test   %r14d,%r14d
jle    128f <main+0xef>
mov    (%rsp),%rax
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0x0(%rbp,%r13,1),%esi
movsbl (%rax,%r13,1),%edx
cmp    %dl,%sil
jne    1270 <main+0xd0>
add    $0x1,%r13
cmp    %r13,%r15
jne    12f0 <main+0x150>
jmp    128f <main+0xef>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Beginning Infection Integration Test...\0A\0A\00"
@.str.1 = [41 x i8] c"Infecting directory (./infection_test):\0A\00"
@.str.2 = [17 x i8] c"./infection_test\00"
@.str.3 = [12 x i8] c"Status: %s\0A\00"
@.str.4 = [3 x i8] c"OK\00"
@.str.5 = [7 x i8] c"Failed\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [19 x i8] c"Reading own bytes\0A\00"
@.str.8 = [16 x i8] c"Byte length:%d\0A\00"
@.str.9 = [14 x i8] c"Comparing...\0A\00"
@.str.10 = [3 x i8] c"rb\00"
@.str.11 = [15 x i8] c"Checking %s...\00"
@.str.12 = [18 x i8] c"failed(%c!=%c) - \00"
@.str.13 = [5 x i8] c"@ %d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
store i32 %14, i32* %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @infectDirectory(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @getOwnBytes(i8** %7, i8* %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%35 = call i8** @walkDir(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i8** %35, i8*** %9
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%37 = load i32, i32* %8
%38 = call i64 @malloc(i32 %37)
%39 = inttoptr i64 %38 to i8*
store i8* %39, i8** %11
store i32 0, i32* %12
br label %40
40: ; preds = %107, %2
%41 = load i8**, i8*** %9
%42 = load i32, i32* %12
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
%45 = load i8*, i8** %44
%46 = getelementptr inbounds i8, i8* %45, i64 0
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %110
50: ; preds = %40
%51 = load i8**, i8*** %9
%52 = load i32, i32* %12
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i32* @fopen(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
store i32* %56, i32** %10
%57 = load i8*, i8** %11
%58 = load i32, i32* %8
%59 = load i32*, i32** %10
%60 = call i32 @fread(i8* %57, i32 1, i32 %58, i32* %59)
%61 = load i8**, i8*** %9
%62 = load i32, i32* %12
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i8*, i8** %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i8* %65)
store i32 0, i32* %13
br label %67
67: ; preds = %102, %50
%68 = load i32, i32* %13
%69 = load i32, i32* %8
%70 = icmp slt i32 %68, %69
br i1 %70, label %71, label %105
71: ; preds = %67
%72 = load i8*, i8** %11
%73 = load i32, i32* %13
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = load i8*, i8** %7
%79 = load i32, i32* %13
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %78, i64 %80
%82 = load i8, i8* %81
%83 = sext i8 %82 to i32
%84 = icmp ne i32 %77, %83
br i1 %84, label %85, label %101
85: ; preds = %71
%86 = load i8*, i8** %11
%87 = load i32, i32* %13
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %86, i64 %88
%90 = load i8, i8* %89
%91 = sext i8 %90 to i32
%92 = load i8*, i8** %7
%93 = load i32, i32* %13
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8, i8* %92, i64 %94
%96 = load i8, i8* %95
%97 = sext i8 %96 to i32
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i32 %91, i32 %97)
%99 = load i32, i32* %13
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0), i32 %99)
br label %105
101: ; preds = %71
br label %102
102: ; preds = %101
%103 = load i32, i32* %13
%104 = add nsw i32 %103, 1
store i32 %104, i32* %13
br label %67
105: ; preds = %85, %67
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %107
107: ; preds = %105
%108 = load i32, i32* %12
%109 = add nsw i32 %108, 1
store i32 %109, i32* %12
br label %40
110: ; preds = %40
%111 = load i8*, i8** %11
%112 = call i32 @free(i8* %111)
%113 = load i8*, i8** %7
%114 = call i32 @free(i8* %113)
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [17 x i8] c"./infection_test\00"
@.str.3 = [12 x i8] c"Status: %s\0A\00"
@.str.4 = [3 x i8] c"OK\00"
@.str.5 = [7 x i8] c"Failed\00"
@.str.8 = [16 x i8] c"Byte length:%d\0A\00"
@.str.10 = [3 x i8] c"rb\00"
@.str.11 = [15 x i8] c"Checking %s...\00"
@.str.12 = [18 x i8] c"failed(%c!=%c) - \00"
@.str.13 = [5 x i8] c"@ %d\00"
@str = [41 x i8] c"Beginning Infection Integration Test...\0A\00"
@str.14 = [40 x i8] c"Infecting directory (./infection_test):\00"
@str.15 = [18 x i8] c"Reading own bytes\00"
@str.16 = [13 x i8] c"Comparing...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.14, i64 0, i64 0))
%6 = load i8*, i8** %1
%7 = tail call i32 @infectDirectory(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%11 = tail call i32 @putchar(i32 10)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.15, i64 0, i64 0))
%13 = bitcast i8** %3 to i8*
%14 = load i8*, i8** %1
%15 = call i32 @getOwnBytes(i8** %3, i8* %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %15)
%17 = call i32 @putchar(i32 10)
%18 = call i8** @walkDir(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.16, i64 0, i64 0))
%20 = call i64 @malloc(i32 %15)
%21 = inttoptr i64 %20 to i8*
%22 = load i8*, i8** %18
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %2
%26 = icmp sgt i32 %15, 0
%27 = zext i32 %15 to i64
br label %33
28: ; preds = %59, %2
%29 = call i32 @free(i8* %21)
%30 = load i8*, i8** %3
%31 = call i32 @free(i8* %30)
%32 = call i32 @putchar(i32 10)
ret i32 0
33: ; preds = %25, %59
%34 = phi i64 [ 0, %25 ], [ %61, %59 ]
%35 = phi i8* [ %22, %25 ], [ %63, %59 ]
%36 = phi i8** [ %18, %25 ], [ %62, %59 ]
%37 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%38 = call i32 @fread(i8* %21, i32 1, i32 %15, i32* %37)
%39 = load i8*, i8** %36
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i8* %39)
br i1 %26, label %41, label %59
41: ; preds = %33
%42 = load i8*, i8** %3
br label %43
43: ; preds = %41, %56
%44 = phi i64 [ 0, %41 ], [ %57, %56 ]
%45 = getelementptr inbounds i8, i8* %21, i64 %44
%46 = load i8, i8* %45
%47 = getelementptr inbounds i8, i8* %42, i64 %44
%48 = load i8, i8* %47
%49 = icmp eq i8 %46, %48
br i1 %49, label %56, label %50
50: ; preds = %43
%51 = trunc i64 %44 to i32
%52 = sext i8 %48 to i32
%53 = sext i8 %46 to i32
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i32 %53, i32 %52)
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0), i32 %51)
br label %59
56: ; preds = %43
%57 = add nuw nsw i64 %44, 1
%58 = icmp eq i64 %57, %27
br i1 %58, label %59, label %43
59: ; preds = %56, %33, %50
%60 = call i32 @putchar(i32 10)
%61 = add nuw i64 %34, 1
%62 = getelementptr inbounds i8*, i8** %18, i64 %61
%63 = load i8*, i8** %62
%64 = load i8, i8* %63
%65 = icmp eq i8 %64, 0
br i1 %65, label %28, label %33
}