#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 chinachip_patch(char *, char *, char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  fprintf(stderr, "ChinaChipPatcher v"
                  "0.1"
                  " - (C) Maurus Cuelenaere 2009"
                  "\n");
  fprintf(stderr, "This is free software; see the source for copying "
                  "conditions. There is NO"
                  "\n");
  fprintf(stderr, "warranty; not even for MERCHANTABILITY or FITNESS FOR A "
                  "PARTICULAR PURPOSE."
                  "\n");
  if (argc < 4) {
    usage(argv[0]);
    return 1;
  }
  return chinachip_patch(argv[1], argv[2], argv[3], argc > 4 ? argv[4] : NULL);
}


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)
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
lea    0xeaa(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xec9(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xeff(%rip),%rsi
call   1040 <fprintf@plt>
cmpl   $0x4,-0x8(%rbp)
jge    11a7 <main+0x77>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1209 <main+0xd9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x4,-0x8(%rbp)
jle    11e6 <main+0xb6>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    11f1 <main+0xc1>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    11f1 <main+0xc1>
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rcx
call   1030 <chinachip_patch@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x2e9f(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xeb5(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xeda(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xf16(%rip),%rsi
call   1040 <fprintf@plt>
cmp    $0x3,%r14d
jg     1186 <main+0x56>
mov    (%rbx),%rdi
call   1050 <usage@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
mov    0x18(%rbx),%rdx
cmp    $0x4,%r14d
jne    119c <main+0x6c>
xor    %ecx,%ecx
jmp    11a0 <main+0x70>
mov    0x20(%rbx),%rcx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <chinachip_patch@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [52 x i8] c"ChinaChipPatcher v0.1 - (C) Maurus Cuelenaere 2009\0A\00"
@.str.1 = [75 x i8] c"This is free software; see the source for copying conditions. There is NO\0A\00"
@.str.2 = [77 x i8] c"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @usage(i8* %17)
store i32 1, i32* %3
br label %39
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 3
%28 = load i8*, i8** %27
%29 = load i32, i32* %4
%30 = icmp sgt i32 %29, 4
br i1 %30, label %31, label %35
31: ; preds = %19
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 4
%34 = load i8*, i8** %33
br label %36
35: ; preds = %19
br label %36
36: ; preds = %35, %31
%37 = phi i8* [ %34, %31 ], [ null, %35 ]
%38 = call i32 @chinachip_patch(i8* %22, i8* %25, i8* %28, i8* %37)
store i32 %38, i32* %3
br label %39
39: ; preds = %36, %14
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [52 x i8] c"ChinaChipPatcher v0.1 - (C) Maurus Cuelenaere 2009\0A\00"
@.str.1 = [75 x i8] c"This is free software; see the source for copying conditions. There is NO\0A\00"
@.str.2 = [77 x i8] c"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @stderr
%4 = tail call i32 @fprintf(i32 %3, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp slt i32 %0, 4
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 @usage(i8* %11)
br label %27
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8*, i8** %1, i64 3
%19 = load i8*, i8** %18
%20 = icmp eq i32 %0, 4
br i1 %20, label %24, label %21
21: ; preds = %13
%22 = getelementptr inbounds i8*, i8** %1, i64 4
%23 = load i8*, i8** %22
br label %24
24: ; preds = %13, %21
%25 = phi i8* [ %23, %21 ], [ null, %13 ]
%26 = tail call i32 @chinachip_patch(i8* %15, i8* %17, i8* %19, i8* %25)
br label %27
27: ; preds = %24, %10
%28 = phi i32 [ 1, %10 ], [ %26, %24 ]
ret i32 %28
}