#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*/ meta;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ puts(char *);
scalar_t__ strlen(char *);
int main(int argc, char **argv) {
  FILE *f;
  char meta[16];
  meta[15] = 0;
  if (argc < 2) {
    puts("usage: patchnap <nap-binary> <meta-server>\n");
    exit(1);
  }
  f = fopen(argv[1], "r+");
  if (!f) {
    perror(argv[1]);
    exit(1);
  }
  fseek(f, 0x004e598, SEEK_SET);
  fread(meta, 1, sizeof(meta) - 1, f);
  printf("we've secretely replace your premium blend (%s) with folger's "
         "crytals (%s).\n",
         meta, argv[2]);
  fseek(f, 0x004e598, SEEK_SET);
  fwrite(argv[2], 1, strlen(argv[2]) + 1, f);
  fclose(f);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x21(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    11d3 <main+0x33>
lea    0xe3c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    120d <main+0x6d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dc8(%rip),%rax
mov    (%rax),%edx
mov    $0x4e598,%esi
call   1080 <fseek@plt>
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0xf,%edx
call   1040 <fread@plt>
lea    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xde1(%rip),%rdi
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d82(%rip),%rax
mov    (%rax),%edx
mov    $0x4e598,%esi
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movb   $0x0,0xf(%rsp)
cmp    $0x1,%edi
jle    125e <main+0xbe>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe65(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1274 <main+0xd4>
mov    %rax,%r12
mov    0x2e01(%rip),%rbx
mov    (%rbx),%edx
mov    %rax,%rdi
mov    $0x4e598,%esi
call   1080 <fseek@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0xf,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    0x10(%r14),%rdx
lea    0xe1e(%rip),%rdi
mov    %r15,%rsi
call   1070 <printf@plt>
mov    (%rbx),%edx
mov    %r12,%rdi
mov    $0x4e598,%esi
call   1080 <fseek@plt>
mov    0x10(%r14),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r12,%rcx
call   10c0 <fwrite@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd9b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x8(%r14),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"usage: patchnap <nap-binary> <meta-server>\0A\00"
@.str.1 = [3 x i8] c"r+\00"
@SEEK_SET = global i32 0
@.str.2 = [77 x i8] c"we've secretely replace your premium blend (%s) with folger's crytals (%s).\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca [16 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 15
store i8 0, i8* %7
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @puts(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = load i8**, i8*** %4
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %5
%18 = load i32*, i32** %5
%19 = icmp ne i32* %18, null
br i1 %19, label %26, label %20
20: ; preds = %13
%21 = load i8**, i8*** %4
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @perror(i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %13
%27 = load i32*, i32** %5
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @fseek(i32* %27, i32 320920, i32 %28)
%30 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%31 = load i32*, i32** %5
%32 = call i32 @fread(i8* %30, i32 1, i32 15, i32* %31)
%33 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%34 = load i8**, i8*** %4
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i32 @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.2, i64 0, i64 0), i8* %33, i8* %36)
%38 = load i32*, i32** %5
%39 = load i32, i32* @SEEK_SET
%40 = call i32 @fseek(i32* %38, i32 320920, i32 %39)
%41 = load i8**, i8*** %4
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = load i8**, i8*** %4
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i64 @strlen(i8* %46)
%48 = add nsw i64 %47, 1
%49 = load i32*, i32** %5
%50 = call i32 @fwrite(i8* %43, i32 1, i64 %48, i32* %49)
%51 = load i32*, i32** %5
%52 = call i32 @fclose(i32* %51)
ret i32 0
}

LLVM IR (-O2):
@.str = [44 x i8] c"usage: patchnap <nap-binary> <meta-server>\0A\00"
@.str.1 = [3 x i8] c"r+\00"
@SEEK_SET = global i32 0
@.str.2 = [77 x i8] c"we've secretely replace your premium blend (%s) with folger's crytals (%s).\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 15
store i8 0, i8* %5
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i8*, i8** %11
%17 = tail call i32 @perror(i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %10
%20 = load i32, i32* @SEEK_SET
%21 = tail call i32 @fseek(i32* %13, i32 320920, i32 %20)
%22 = call i32 @fread(i8* %4, i32 1, i32 15, i32* %13)
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.2, i64 0, i64 0), i8* %4, i8* %24)
%26 = load i32, i32* @SEEK_SET
%27 = call i32 @fseek(i32* %13, i32 320920, i32 %26)
%28 = load i8*, i8** %23
%29 = call i64 @strlen(i8* dereferenceable(1) %28)
%30 = add nsw i64 %29, 1
%31 = call i32 @fwrite(i8* %28, i32 1, i64 %30, i32* %13)
%32 = call i32 @fclose(i32* %13)
ret i32 0
}