#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*/ binpatch(char *, char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  int i;
  if (argc < 3) {
    printf("Usage: binpatch <old-string> <new-string> <filename>...\n");
    exit(1);
  }
  for (i = 3; i < argc; i++)
    binpatch(argv[1], argv[2], argv[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1166 <main+0x36>
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
movl   $0x3,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a8 <main+0x78>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
call   1050 <binpatch@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116d <main+0x3d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x3,%edi
jl     1172 <main+0x42>
je     116a <main+0x3a>
mov    %rsi,%r15
mov    %edi,%r14d
mov    $0x3,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x8(%r15),%rdi
mov    0x10(%r15),%rsi
mov    (%r15,%rbx,8),%rdx
call   1050 <binpatch@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <main+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [57 x i8] c"Usage: binpatch <old-string> <new-string> <filename>...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
store i32 3, i32* %6
br label %13
13: ; preds = %30, %12
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %33
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = load i8**, i8*** %5
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @binpatch(i8* %20, i8* %23, i8* %28)
br label %30
30: ; preds = %17
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %13
33: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@str = [56 x i8] c"Usage: binpatch <old-string> <new-string> <filename>...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = icmp eq i32 %0, 3
br i1 %5, label %22, label %6
6: ; preds = %4
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = zext i32 %0 to i64
br label %13
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %6, %13
%14 = phi i64 [ 3, %6 ], [ %20, %13 ]
%15 = load i8*, i8** %7
%16 = load i8*, i8** %8
%17 = getelementptr inbounds i8*, i8** %1, i64 %14
%18 = load i8*, i8** %17
%19 = tail call i32 @binpatch(i8* %15, i8* %16, i8* %18)
%20 = add nuw nsw i64 %14, 1
%21 = icmp eq i64 %20, %9
br i1 %21, label %22, label %13
22: ; preds = %13, %4
ret i32 0
}