#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*/ O_RDONLY;
int /*<<< orphan*/ analyze(unsigned char *, unsigned int, unsigned char *,
                           unsigned int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(unsigned char *);
int open(char *, int /*<<< orphan*/);
unsigned int read(int, unsigned char *, int);
scalar_t__ sci_malloc(int);
int main(int argc, char **argv) {
  int fd1, fd2;
  unsigned char *patch001;
  unsigned char *patch004;
  unsigned int length001, length004;
  if (argc < 2)
    return -1;
  if ((fd1 = open(argv[1], O_RDONLY)) < 0)
    return -1;
  if ((fd2 = open(argv[2], O_RDONLY)) < 0) {
    close(fd1);
    return -1;
  }
  patch001 = (unsigned char *)sci_malloc(65536);
  length001 = read(fd1, patch001, 65536);
  close(fd1);
  patch004 = (unsigned char *)sci_malloc(65536);
  length004 = read(fd2, patch004, 65536);
  close(fd2);
  if (patch001[0] == 0x89 && patch001[1] == 0x00)
    if (patch004[0] == 0x89 && patch004[1] == 0x00)
      analyze(patch001 + 2, length001 - 2, patch004 + 2, length004 - 2);
    else
      analyze(patch001 + 2, length001 - 2, patch004, length004);
  else if (patch004[0] == 0x89 && patch004[1] == 0x00)
    analyze(patch001, length001, patch004 + 2, length004 - 2);
  else
    analyze(patch001, length001, patch004, length004);
  free(patch001);
  free(patch004);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118c <main+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1342 <main+0x1e2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11ba <main+0x5a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1342 <main+0x1e2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11f0 <main+0x90>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1342 <main+0x1e2>
mov    $0x10000,%edi
call   1070 <sci_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x10000,%edx
call   1060 <read@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    $0x10000,%edi
call   1070 <sci_malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x10000,%edx
call   1060 <read@plt>
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x89,%eax
jne    12cf <main+0x16f>
mov    -0x20(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    12cf <main+0x16f>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x89,%eax
jne    12b0 <main+0x150>
mov    -0x28(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    12b0 <main+0x150>
mov    -0x20(%rbp),%rdi
add    $0x2,%rdi
mov    -0x2c(%rbp),%esi
sub    $0x2,%esi
mov    -0x28(%rbp),%rdx
add    $0x2,%rdx
mov    -0x30(%rbp),%ecx
sub    $0x2,%ecx
call   1040 <analyze@plt>
jmp    12ca <main+0x16a>
mov    -0x20(%rbp),%rdi
add    $0x2,%rdi
mov    -0x2c(%rbp),%esi
sub    $0x2,%esi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%ecx
call   1040 <analyze@plt>
jmp    1329 <main+0x1c9>
mov    -0x28(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x89,%eax
jne    1311 <main+0x1b1>
mov    -0x28(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1311 <main+0x1b1>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdx
add    $0x2,%rdx
mov    -0x30(%rbp),%ecx
sub    $0x2,%ecx
call   1040 <analyze@plt>
jmp    1324 <main+0x1c4>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%ecx
call   1040 <analyze@plt>
jmp    1329 <main+0x1c9>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%ebx
cmp    $0x2,%edi
jl     1246 <main+0xe6>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
mov    0x2e61(%rip),%r14
mov    (%r14),%esi
call   1080 <open@plt>
test   %eax,%eax
js     1246 <main+0xe6>
mov    %eax,%r12d
mov    0x10(%rbp),%rdi
mov    (%r14),%esi
call   1080 <open@plt>
test   %eax,%eax
js     123e <main+0xde>
mov    %eax,%r13d
mov    $0x10000,%edi
call   1070 <sci_malloc@plt>
mov    %rax,%r14
mov    %r12d,%edi
mov    %rax,%rsi
mov    $0x10000,%edx
call   1060 <read@plt>
mov    %eax,%r15d
mov    %r12d,%edi
call   1050 <close@plt>
mov    $0x10000,%edi
call   1070 <sci_malloc@plt>
mov    %rax,%rbx
mov    %r13d,%edi
mov    %rax,%rsi
mov    $0x10000,%edx
call   1060 <read@plt>
mov    %eax,%r12d
mov    %r13d,%edi
call   1050 <close@plt>
cmpb   $0x89,(%r14)
jne    120e <main+0xae>
cmpb   $0x0,0x1(%r14)
je     1257 <main+0xf7>
cmpb   $0x89,(%rbx)
jne    1219 <main+0xb9>
cmpb   $0x0,0x1(%rbx)
je     126f <main+0x10f>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
mov    %r12d,%ecx
call   1040 <analyze@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
jmp    1246 <main+0xe6>
mov    %r12d,%edi
call   1050 <close@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmpb   $0x89,(%rbx)
jne    1262 <main+0x102>
cmpb   $0x0,0x1(%rbx)
je     1282 <main+0x122>
mov    %r14,%rdi
add    $0x2,%rdi
add    $0xfffffffe,%r15d
jmp    121c <main+0xbc>
mov    %rbx,%rdx
add    $0x2,%rdx
add    $0xfffffffe,%r12d
mov    %r14,%rdi
mov    %r15d,%esi
jmp    1222 <main+0xc2>
mov    %r14,%rdi
add    $0x2,%rdi
add    $0xfffffffe,%r15d
mov    %rbx,%rdx
add    $0x2,%rdx
add    $0xfffffffe,%r12d
mov    %r15d,%esi
jmp    1222 <main+0xc2>

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %122
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %15
store i32 -1, i32* %3
br label %122
23: ; preds = %15
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* %26, i32 %27)
store i32 %28, i32* %7
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %23
%31 = load i32, i32* %6
%32 = call i32 @close(i32 %31)
store i32 -1, i32* %3
br label %122
33: ; preds = %23
%34 = call i64 @sci_malloc(i32 65536)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %8
%36 = load i32, i32* %6
%37 = load i8*, i8** %8
%38 = call i32 @read(i32 %36, i8* %37, i32 65536)
store i32 %38, i32* %10
%39 = load i32, i32* %6
%40 = call i32 @close(i32 %39)
%41 = call i64 @sci_malloc(i32 65536)
%42 = inttoptr i64 %41 to i8*
store i8* %42, i8** %9
%43 = load i32, i32* %7
%44 = load i8*, i8** %9
%45 = call i32 @read(i32 %43, i8* %44, i32 65536)
store i32 %45, i32* %11
%46 = load i32, i32* %7
%47 = call i32 @close(i32 %46)
%48 = load i8*, i8** %8
%49 = getelementptr inbounds i8, i8* %48, i64 0
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = icmp eq i32 %51, 137
br i1 %52, label %53, label %90
53: ; preds = %33
%54 = load i8*, i8** %8
%55 = getelementptr inbounds i8, i8* %54, i64 1
%56 = load i8, i8* %55
%57 = zext i8 %56 to i32
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %90
59: ; preds = %53
%60 = load i8*, i8** %9
%61 = getelementptr inbounds i8, i8* %60, i64 0
%62 = load i8, i8* %61
%63 = zext i8 %62 to i32
%64 = icmp eq i32 %63, 137
br i1 %64, label %65, label %81
65: ; preds = %59
%66 = load i8*, i8** %9
%67 = getelementptr inbounds i8, i8* %66, i64 1
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %81
71: ; preds = %65
%72 = load i8*, i8** %8
%73 = getelementptr inbounds i8, i8* %72, i64 2
%74 = load i32, i32* %10
%75 = sub i32 %74, 2
%76 = load i8*, i8** %9
%77 = getelementptr inbounds i8, i8* %76, i64 2
%78 = load i32, i32* %11
%79 = sub i32 %78, 2
%80 = call i32 @analyze(i8* %73, i32 %75, i8* %77, i32 %79)
br label %89
81: ; preds = %65, %59
%82 = load i8*, i8** %8
%83 = getelementptr inbounds i8, i8* %82, i64 2
%84 = load i32, i32* %10
%85 = sub i32 %84, 2
%86 = load i8*, i8** %9
%87 = load i32, i32* %11
%88 = call i32 @analyze(i8* %83, i32 %85, i8* %86, i32 %87)
br label %89
89: ; preds = %81, %71
br label %117
90: ; preds = %53, %33
%91 = load i8*, i8** %9
%92 = getelementptr inbounds i8, i8* %91, i64 0
%93 = load i8, i8* %92
%94 = zext i8 %93 to i32
%95 = icmp eq i32 %94, 137
br i1 %95, label %96, label %110
96: ; preds = %90
%97 = load i8*, i8** %9
%98 = getelementptr inbounds i8, i8* %97, i64 1
%99 = load i8, i8* %98
%100 = zext i8 %99 to i32
%101 = icmp eq i32 %100, 0
br i1 %101, label %102, label %110
102: ; preds = %96
%103 = load i8*, i8** %8
%104 = load i32, i32* %10
%105 = load i8*, i8** %9
%106 = getelementptr inbounds i8, i8* %105, i64 2
%107 = load i32, i32* %11
%108 = sub i32 %107, 2
%109 = call i32 @analyze(i8* %103, i32 %104, i8* %106, i32 %108)
br label %116
110: ; preds = %96, %90
%111 = load i8*, i8** %8
%112 = load i32, i32* %10
%113 = load i8*, i8** %9
%114 = load i32, i32* %11
%115 = call i32 @analyze(i8* %111, i32 %112, i8* %113, i32 %114)
br label %116
116: ; preds = %110, %102
br label %117
117: ; preds = %116, %89
%118 = load i8*, i8** %8
%119 = call i32 @free(i8* %118)
%120 = load i8*, i8** %9
%121 = call i32 @free(i8* %120)
store i32 0, i32* %3
br label %122
122: ; preds = %117, %30, %22, %14
%123 = load i32, i32* %3
ret i32 %123
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %66, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %6, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %66, label %10
10: ; preds = %4
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = tail call i32 @close(i32 %8)
br label %66
18: ; preds = %10
%19 = tail call i64 @sci_malloc(i32 65536)
%20 = inttoptr i64 %19 to i8*
%21 = tail call i32 @read(i32 %8, i8* %20, i32 65536)
%22 = tail call i32 @close(i32 %8)
%23 = tail call i64 @sci_malloc(i32 65536)
%24 = inttoptr i64 %23 to i8*
%25 = tail call i32 @read(i32 %14, i8* %24, i32 65536)
%26 = tail call i32 @close(i32 %14)
%27 = load i8, i8* %20
%28 = icmp eq i8 %27, -119
br i1 %28, label %29, label %50
29: ; preds = %18
%30 = getelementptr inbounds i8, i8* %20, i64 1
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %33, label %50
33: ; preds = %29
%34 = load i8, i8* %24
%35 = icmp eq i8 %34, -119
br i1 %35, label %36, label %46
36: ; preds = %33
%37 = getelementptr inbounds i8, i8* %24, i64 1
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %36
%41 = getelementptr inbounds i8, i8* %20, i64 2
%42 = add i32 %21, -2
%43 = getelementptr inbounds i8, i8* %24, i64 2
%44 = add i32 %25, -2
%45 = tail call i32 @analyze(i8* %41, i32 %42, i8* %43, i32 %44)
br label %63
46: ; preds = %36, %33
%47 = getelementptr inbounds i8, i8* %20, i64 2
%48 = add i32 %21, -2
%49 = tail call i32 @analyze(i8* %47, i32 %48, i8* %24, i32 %25)
br label %63
50: ; preds = %29, %18
%51 = load i8, i8* %24
%52 = icmp eq i8 %51, -119
br i1 %52, label %53, label %61
53: ; preds = %50
%54 = getelementptr inbounds i8, i8* %24, i64 1
%55 = load i8, i8* %54
%56 = icmp eq i8 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %53
%58 = getelementptr inbounds i8, i8* %24, i64 2
%59 = add i32 %25, -2
%60 = tail call i32 @analyze(i8* %20, i32 %21, i8* %58, i32 %59)
br label %63
61: ; preds = %53, %50
%62 = tail call i32 @analyze(i8* %20, i32 %21, i8* %24, i32 %25)
br label %63
63: ; preds = %57, %61, %40, %46
%64 = tail call i32 @free(i8* %20)
%65 = tail call i32 @free(i8* %24)
br label %66
66: ; preds = %4, %2, %63, %16
%67 = phi i32 [ -1, %16 ], [ 0, %63 ], [ -1, %2 ], [ -1, %4 ]
ret i32 %67
}