#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int sscanf(char *, char *, char *, long *, long *);
int /*<<< orphan*/ stderr;
int applyPatch(FILE *patchFile, FILE *originalFile) {
  char buffer[100];
  char instruction;
  long int k, m, i;
  long int current = 0;
  long int previous = 0;
  int res;
  char *str_patch = NULL;
  char *str_file = NULL;
  size_t len_patch = 0;
  size_t len_file = 0;
  while (fgets(buffer, 100, patchFile) != NULL) {
    res = sscanf(buffer, "%c %ld %ld", &instruction, &k, &m);
    if (res < 2) {
      fprintf(stderr,
              "!!!!! instruction must be followed by a line number  !!!!!\n");
      exit(EXIT_FAILURE);
    }
    current = k;
    if (current < previous) {
      fprintf(stderr, "!!!!! k must be increasing  !!!!!\n");
      exit(EXIT_FAILURE);
    }
    switch (instruction) {
    case '+':
      getline(&str_patch, &len_patch, patchFile);
      if (k == 0)
        printf("%s", str_patch);
      else {
        for (i = 0; i < current - previous; i++) {
          getline(&str_file, &len_file, originalFile);
          printf("%s", str_file);
        }
        printf("%s", str_patch);
      }
      previous = current;
      break;
    case '=':
      if (current <= previous) {
        fprintf(stderr, "!!!!! k must be strictly increasing for =  !!!!!\n");
        exit(EXIT_FAILURE);
      }
      getline(&str_patch, &len_patch, patchFile);
      for (i = 0; i < current - previous; i++) {
        getline(&str_file, &len_file, originalFile);
        if (i < current - previous - 1)
          printf("%s", str_file);
      }
      printf("%s", str_patch);
      previous = current;
      break;
    case 'd':
      for (i = 0; i < current - previous; i++) {
        getline(&str_file, &len_file, originalFile);
        if (i < current - previous - 1)
          printf("%s", str_file);
      }
      previous = current;
      break;
    case 'D':
      if (res < 3) {
        fprintf(stderr, "!!!!! m of D k m  is missing  !!!!!\n");
        exit(EXIT_FAILURE);
      }
      for (i = 0; i < current - previous - 1; i++) {
        getline(&str_file, &len_file, originalFile);
        printf("%s", str_file);
      }
      for (i = 0; i < m; i++)
        getline(&str_file, &len_file, originalFile);
      previous = current + m - 1;
      break;
    default:
      fprintf(stderr, "!!!!! patchFile Format Error !!!!!\n");
      exit(EXIT_FAILURE);
      break;
    }
  }
  while (getline(&str_file, &len_file, originalFile) != -1)
    printf("%s", str_file);
  free(str_patch);
  free(str_file);
  return 0;
}


x86 assembly (clang, -O0):
<applyPatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0xa8(%rbp)
movq   $0x0,-0xb0(%rbp)
movq   $0x0,-0xc0(%rbp)
movq   $0x0,-0xc8(%rbp)
movq   $0x0,-0xd0(%rbp)
movq   $0x0,-0xd8(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     167f <applyPatch+0x50f>
lea    -0x80(%rbp),%rdi
lea    0xe14(%rip),%rsi
lea    -0x81(%rbp),%rdx
lea    -0x90(%rbp),%rcx
lea    -0x98(%rbp),%r8
call   1070 <sscanf@plt>
mov    %eax,-0xb4(%rbp)
cmpl   $0x2,-0xb4(%rbp)
jge    123c <applyPatch+0xcc>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x90(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0xa8(%rbp),%rax
cmp    -0xb0(%rbp),%rax
jge    1281 <applyPatch+0x111>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movsbl -0x81(%rbp),%eax
mov    %eax,-0xdc(%rbp)
sub    $0x2b,%eax
je     12d8 <applyPatch+0x168>
jmp    129c <applyPatch+0x12c>
mov    -0xdc(%rbp),%eax
sub    $0x3d,%eax
je     13a5 <applyPatch+0x235>
jmp    12b0 <applyPatch+0x140>
mov    -0xdc(%rbp),%eax
sub    $0x44,%eax
je     154e <applyPatch+0x3de>
jmp    12c4 <applyPatch+0x154>
mov    -0xdc(%rbp),%eax
sub    $0x64,%eax
je     14aa <applyPatch+0x33a>
jmp    1657 <applyPatch+0x4e7>
mov    -0x8(%rbp),%rdx
lea    -0xc0(%rbp),%rdi
lea    -0xd0(%rbp),%rsi
call   1080 <getline@plt>
cmpq   $0x0,-0x90(%rbp)
jne    1315 <applyPatch+0x1a5>
mov    -0xc0(%rbp),%rsi
lea    0xd5f(%rip),%rdi
call   1040 <printf@plt>
jmp    1392 <applyPatch+0x222>
movq   $0x0,-0xa0(%rbp)
mov    -0xa0(%rbp),%rax
mov    -0xa8(%rbp),%rcx
sub    -0xb0(%rbp),%rcx
cmp    %rcx,%rax
jge    137f <applyPatch+0x20f>
mov    -0x10(%rbp),%rdx
lea    -0xc8(%rbp),%rdi
lea    -0xd8(%rbp),%rsi
call   1080 <getline@plt>
mov    -0xc8(%rbp),%rsi
lea    0xd07(%rip),%rdi
call   1040 <printf@plt>
mov    -0xa0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xa0(%rbp)
jmp    1320 <applyPatch+0x1b0>
mov    -0xc0(%rbp),%rsi
lea    0xcdd(%rip),%rdi
call   1040 <printf@plt>
mov    -0xa8(%rbp),%rax
mov    %rax,-0xb0(%rbp)
jmp    167a <applyPatch+0x50a>
mov    -0xa8(%rbp),%rax
cmp    -0xb0(%rbp),%rax
jg     13dc <applyPatch+0x26c>
mov    0x2c20(%rip),%rax
mov    (%rax),%edi
lea    0xca4(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2c03(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rdx
lea    -0xc0(%rbp),%rdi
lea    -0xd0(%rbp),%rsi
call   1080 <getline@plt>
movq   $0x0,-0xa0(%rbp)
mov    -0xa0(%rbp),%rax
mov    -0xa8(%rbp),%rcx
sub    -0xb0(%rbp),%rcx
cmp    %rcx,%rax
jge    1484 <applyPatch+0x314>
mov    -0x10(%rbp),%rdx
lea    -0xc8(%rbp),%rdi
lea    -0xd8(%rbp),%rsi
call   1080 <getline@plt>
mov    -0xa0(%rbp),%rax
mov    -0xa8(%rbp),%rcx
sub    -0xb0(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jge    1468 <applyPatch+0x2f8>
mov    -0xc8(%rbp),%rsi
lea    0xc07(%rip),%rdi
call   1040 <printf@plt>
jmp    146d <applyPatch+0x2fd>
mov    -0xa0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xa0(%rbp)
jmp    13fe <applyPatch+0x28e>
mov    -0xc0(%rbp),%rsi
lea    0xbd8(%rip),%rdi
call   1040 <printf@plt>
mov    -0xa8(%rbp),%rax
mov    %rax,-0xb0(%rbp)
jmp    167a <applyPatch+0x50a>
movq   $0x0,-0xa0(%rbp)
mov    -0xa0(%rbp),%rax
mov    -0xa8(%rbp),%rcx
sub    -0xb0(%rbp),%rcx
cmp    %rcx,%rax
jge    153b <applyPatch+0x3cb>
mov    -0x10(%rbp),%rdx
lea    -0xc8(%rbp),%rdi
lea    -0xd8(%rbp),%rsi
call   1080 <getline@plt>
mov    -0xa0(%rbp),%rax
mov    -0xa8(%rbp),%rcx
sub    -0xb0(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jge    151f <applyPatch+0x3af>
mov    -0xc8(%rbp),%rsi
lea    0xb50(%rip),%rdi
call   1040 <printf@plt>
jmp    1524 <applyPatch+0x3b4>
mov    -0xa0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xa0(%rbp)
jmp    14b5 <applyPatch+0x345>
mov    -0xa8(%rbp),%rax
mov    %rax,-0xb0(%rbp)
jmp    167a <applyPatch+0x50a>
cmpl   $0x3,-0xb4(%rbp)
jge    157e <applyPatch+0x40e>
mov    0x2a7e(%rip),%rax
mov    (%rax),%edi
lea    0xb34(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2a61(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movq   $0x0,-0xa0(%rbp)
mov    -0xa0(%rbp),%rax
mov    -0xa8(%rbp),%rcx
sub    -0xb0(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jge    15ec <applyPatch+0x47c>
mov    -0x10(%rbp),%rdx
lea    -0xc8(%rbp),%rdi
lea    -0xd8(%rbp),%rsi
call   1080 <getline@plt>
mov    -0xc8(%rbp),%rsi
lea    0xa9a(%rip),%rdi
call   1040 <printf@plt>
mov    -0xa0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xa0(%rbp)
jmp    1589 <applyPatch+0x419>
movq   $0x0,-0xa0(%rbp)
mov    -0xa0(%rbp),%rax
cmp    -0x98(%rbp),%rax
jge    1639 <applyPatch+0x4c9>
mov    -0x10(%rbp),%rdx
lea    -0xc8(%rbp),%rdi
lea    -0xd8(%rbp),%rsi
call   1080 <getline@plt>
mov    -0xa0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xa0(%rbp)
jmp    15f7 <applyPatch+0x487>
mov    -0xa8(%rbp),%rax
add    -0x98(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0xb0(%rbp)
jmp    167a <applyPatch+0x50a>
mov    0x2982(%rip),%rax
mov    (%rax),%edi
lea    0xa5d(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2965(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11c5 <applyPatch+0x55>
jmp    1684 <applyPatch+0x514>
mov    -0x10(%rbp),%rdx
lea    -0xc8(%rbp),%rdi
lea    -0xd8(%rbp),%rsi
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     16bc <applyPatch+0x54c>
mov    -0xc8(%rbp),%rsi
lea    0x9b8(%rip),%rdi
call   1040 <printf@plt>
jmp    1684 <applyPatch+0x514>
mov    -0xc0(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc8(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<applyPatch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %rsi,%rbp
mov    %rdi,%rdx
movq   $0x0,0x20(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x38(%rsp)
movq   $0x0,0x30(%rsp)
lea    0x50(%rsp),%rdi
mov    $0x64,%esi
mov    %rdx,0x18(%rsp)
call   1050 <fgets@plt>
test   %rax,%rax
je     14d6 <applyPatch+0x366>
xor    %r12d,%r12d
lea    0x50(%rsp),%r14
lea    0x8(%rsp),%r15
lea    0x30(%rsp),%r13
mov    %rbp,0x10(%rsp)
jmp    122d <applyPatch+0xbd>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x20(%rsp),%rsi
mov    %r12,%rdi
call   1040 <printf@plt>
mov    0x18(%rsp),%r12
lea    0x50(%rsp),%r14
mov    0x10(%rsp),%rbp
mov    0x28(%rsp),%rbx
mov    %r14,%rdi
mov    $0x64,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
mov    %rbx,%r12
test   %rax,%rax
je     14d6 <applyPatch+0x366>
mov    %r14,%rdi
lea    0xdc9(%rip),%rsi
lea    0x7(%rsp),%rdx
lea    0x48(%rsp),%rcx
lea    0x40(%rsp),%r8
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jle    1558 <applyPatch+0x3e8>
mov    0x48(%rsp),%rbx
mov    %rbx,%r14
sub    %r12,%r14
jl     156a <applyPatch+0x3fa>
movsbl 0x7(%rsp),%ecx
cmp    $0x43,%ecx
jg     1310 <applyPatch+0x1a0>
cmp    $0x2b,%ecx
je     1380 <applyPatch+0x210>
cmp    $0x3d,%ecx
jne    157c <applyPatch+0x40c>
mov    %rbx,0x28(%rsp)
mov    %rbx,%rbp
sub    %r12,%rbp
jle    15a0 <applyPatch+0x430>
lea    0x20(%rsp),%rdi
lea    0x38(%rsp),%rsi
mov    0x18(%rsp),%rdx
call   1080 <getline@plt>
test   %rbp,%rbp
lea    0xdb6(%rip),%r12
jle    11f0 <applyPatch+0x80>
lea    -0x1(%rbp),%r14
xor    %ebx,%ebx
jmp    12dd <applyPatch+0x16d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11f0 <applyPatch+0x80>
mov    %r15,%rdi
mov    %r13,%rsi
mov    0x10(%rsp),%rdx
call   1080 <getline@plt>
cmp    %r14,%rbx
jge    12d0 <applyPatch+0x160>
mov    0x8(%rsp),%rsi
mov    %r12,%rdi
call   1040 <printf@plt>
jmp    12d0 <applyPatch+0x160>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x44,%ecx
je     1410 <applyPatch+0x2a0>
cmp    $0x64,%ecx
jne    157c <applyPatch+0x40c>
test   %r14,%r14
lea    0xd3e(%rip),%r12
jle    14a2 <applyPatch+0x332>
mov    %rbx,0x28(%rsp)
lea    -0x1(%r14),%rbp
xor    %ebx,%ebx
jmp    134d <applyPatch+0x1dd>
nop
add    $0x1,%rbx
cmp    %rbx,%r14
je     11fd <applyPatch+0x8d>
mov    %r15,%rdi
mov    %r13,%rsi
mov    0x10(%rsp),%rdx
call   1080 <getline@plt>
cmp    %rbp,%rbx
jge    1340 <applyPatch+0x1d0>
mov    0x8(%rsp),%rsi
mov    %r12,%rdi
call   1040 <printf@plt>
jmp    1340 <applyPatch+0x1d0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x20(%rsp),%rdi
lea    0x38(%rsp),%rsi
mov    0x18(%rsp),%r12
mov    %r12,%rdx
call   1080 <getline@plt>
cmpq   $0x0,0x48(%rsp)
je     14b6 <applyPatch+0x346>
mov    %rbx,%r12
test   %r14,%r14
lea    0xcba(%rip),%rbp
mov    0x10(%rsp),%rbx
jle    13e1 <applyPatch+0x271>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1080 <getline@plt>
mov    0x8(%rsp),%rsi
mov    %rbp,%rdi
call   1040 <printf@plt>
add    $0xffffffffffffffff,%r14
jne    13c0 <applyPatch+0x250>
mov    0x20(%rsp),%rsi
mov    %rbp,%rdi
call   1040 <printf@plt>
lea    0x50(%rsp),%r14
mov    %rbx,%rbp
mov    %r12,%rbx
mov    0x18(%rsp),%r12
jmp    1211 <applyPatch+0xa1>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x3,%eax
jb     158e <applyPatch+0x41e>
not    %r12
mov    %rbx,0x28(%rsp)
add    %rbx,%r12
test   %r12,%r12
lea    0x50(%rsp),%r14
lea    0xc37(%rip),%rbx
mov    0x10(%rsp),%rbp
jle    1461 <applyPatch+0x2f1>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1080 <getline@plt>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <printf@plt>
add    $0xffffffffffffffff,%r12
jne    1440 <applyPatch+0x2d0>
mov    0x40(%rsp),%rax
test   %rax,%rax
jle    148c <applyPatch+0x31c>
xor    %ebx,%ebx
nopl   (%rax)
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1080 <getline@plt>
add    $0x1,%rbx
mov    0x40(%rsp),%rax
cmp    %rax,%rbx
jl     1470 <applyPatch+0x300>
mov    0x28(%rsp),%rbx
add    %rax,%rbx
add    $0xffffffffffffffff,%rbx
mov    0x18(%rsp),%r12
jmp    1211 <applyPatch+0xa1>
lea    0x50(%rsp),%r14
mov    0x10(%rsp),%rbp
mov    0x18(%rsp),%r12
jmp    1211 <applyPatch+0xa1>
mov    0x20(%rsp),%rsi
lea    0xba8(%rip),%rdi
call   1040 <printf@plt>
lea    0x50(%rsp),%r14
mov    0x10(%rsp),%rbp
jmp    1211 <applyPatch+0xa1>
lea    0x8(%rsp),%rdi
lea    0x30(%rsp),%rsi
mov    %rbp,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     1530 <applyPatch+0x3c0>
mov    %rbp,%rbx
lea    0xb73(%rip),%r14
lea    0x8(%rsp),%r15
lea    0x30(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
jne    1510 <applyPatch+0x3a0>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2a81(%rip),%rax
mov    (%rax),%edi
lea    0xaa3(%rip),%rsi
jmp    15b0 <applyPatch+0x440>
mov    0x2a6f(%rip),%rax
mov    (%rax),%edi
lea    0xacd(%rip),%rsi
jmp    15b0 <applyPatch+0x440>
mov    0x2a5d(%rip),%rax
mov    (%rax),%edi
lea    0xb38(%rip),%rsi
jmp    15b0 <applyPatch+0x440>
mov    0x2a4b(%rip),%rax
mov    (%rax),%edi
lea    0xb01(%rip),%rsi
jmp    15b0 <applyPatch+0x440>
mov    0x2a39(%rip),%rax
mov    (%rax),%edi
lea    0xabd(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2a1c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"%c %ld %ld\00"
@stderr = global i32 0
@.str.1 = [60 x i8] c"!!!!! instruction must be followed by a line number !!!!!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [35 x i8] c"!!!!! k must be increasing !!!!!\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [50 x i8] c"!!!!! k must be strictly increasing for = !!!!!\0A\00"
@.str.5 = [37 x i8] c"!!!!! m of D k m is missing !!!!!\0A\00"
@.str.6 = [36 x i8] c"!!!!! patchFile Format Error !!!!!\0A\00"
define i32 @applyPatch(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [100 x i8]
%6 = alloca i8
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i64
store i32* %0, i32** %3
store i32* %1, i32** %4
store i64 0, i64* %10
store i64 0, i64* %11
store i8* null, i8** %13
store i8* null, i8** %14
store i64 0, i64* %15
store i64 0, i64* %16
br label %17
17: ; preds = %181, %2
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%19 = load i32*, i32** %3
%20 = call i32* @fgets(i8* %18, i32 100, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %182
22: ; preds = %17
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%24 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %6, i64* %7, i64* %8)
store i32 %24, i32* %12
%25 = load i32, i32* %12
%26 = icmp slt i32 %25, 2
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %22
%33 = load i64, i64* %7
store i64 %33, i64* %10
%34 = load i64, i64* %10
%35 = load i64, i64* %11
%36 = icmp slt i64 %34, %35
br i1 %36, label %37, label %42
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %32
%43 = load i8, i8* %6
%44 = sext i8 %43 to i32
switch i32 %44, label %176 [
i32 43, label %45
i32 61, label %73
i32 100, label %111
i32 68, label %136
]
45: ; preds = %42
%46 = load i32*, i32** %3
%47 = call i32 @getline(i8** %13, i64* %15, i32* %46)
%48 = load i64, i64* %7
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = load i8*, i8** %13
%52 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %51)
br label %71
53: ; preds = %45
store i64 0, i64* %9
br label %54
54: ; preds = %65, %53
%55 = load i64, i64* %9
%56 = load i64, i64* %10
%57 = load i64, i64* %11
%58 = sub nsw i64 %56, %57
%59 = icmp slt i64 %55, %58
br i1 %59, label %60, label %68
60: ; preds = %54
%61 = load i32*, i32** %4
%62 = call i32 @getline(i8** %14, i64* %16, i32* %61)
%63 = load i8*, i8** %14
%64 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %60
%66 = load i64, i64* %9
%67 = add nsw i64 %66, 1
store i64 %67, i64* %9
br label %54
68: ; preds = %54
%69 = load i8*, i8** %13
%70 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %69)
br label %71
71: ; preds = %68, %50
%72 = load i64, i64* %10
store i64 %72, i64* %11
br label %181
73: ; preds = %42
%74 = load i64, i64* %10
%75 = load i64, i64* %11
%76 = icmp sle i64 %74, %75
br i1 %76, label %77, label %82
77: ; preds = %73
%78 = load i32, i32* @stderr
%79 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0))
%80 = load i32, i32* @EXIT_FAILURE
%81 = call i32 @exit(i32 %80)
unreachable
82: ; preds = %73
%83 = load i32*, i32** %3
%84 = call i32 @getline(i8** %13, i64* %15, i32* %83)
store i64 0, i64* %9
br label %85
85: ; preds = %104, %82
%86 = load i64, i64* %9
%87 = load i64, i64* %10
%88 = load i64, i64* %11
%89 = sub nsw i64 %87, %88
%90 = icmp slt i64 %86, %89
br i1 %90, label %91, label %107
91: ; preds = %85
%92 = load i32*, i32** %4
%93 = call i32 @getline(i8** %14, i64* %16, i32* %92)
%94 = load i64, i64* %9
%95 = load i64, i64* %10
%96 = load i64, i64* %11
%97 = sub nsw i64 %95, %96
%98 = sub nsw i64 %97, 1
%99 = icmp slt i64 %94, %98
br i1 %99, label %100, label %103
100: ; preds = %91
%101 = load i8*, i8** %14
%102 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %101)
br label %103
103: ; preds = %100, %91
br label %104
104: ; preds = %103
%105 = load i64, i64* %9
%106 = add nsw i64 %105, 1
store i64 %106, i64* %9
br label %85
107: ; preds = %85
%108 = load i8*, i8** %13
%109 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %108)
%110 = load i64, i64* %10
store i64 %110, i64* %11
br label %181
111: ; preds = %42
store i64 0, i64* %9
br label %112
112: ; preds = %131, %111
%113 = load i64, i64* %9
%114 = load i64, i64* %10
%115 = load i64, i64* %11
%116 = sub nsw i64 %114, %115
%117 = icmp slt i64 %113, %116
br i1 %117, label %118, label %134
118: ; preds = %112
%119 = load i32*, i32** %4
%120 = call i32 @getline(i8** %14, i64* %16, i32* %119)
%121 = load i64, i64* %9
%122 = load i64, i64* %10
%123 = load i64, i64* %11
%124 = sub nsw i64 %122, %123
%125 = sub nsw i64 %124, 1
%126 = icmp slt i64 %121, %125
br i1 %126, label %127, label %130
127: ; preds = %118
%128 = load i8*, i8** %14
%129 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %128)
br label %130
130: ; preds = %127, %118
br label %131
131: ; preds = %130
%132 = load i64, i64* %9
%133 = add nsw i64 %132, 1
store i64 %133, i64* %9
br label %112
134: ; preds = %112
%135 = load i64, i64* %10
store i64 %135, i64* %11
br label %181
136: ; preds = %42
%137 = load i32, i32* %12
%138 = icmp slt i32 %137, 3
br i1 %138, label %139, label %144
139: ; preds = %136
%140 = load i32, i32* @stderr
%141 = call i32 @fprintf(i32 %140, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%142 = load i32, i32* @EXIT_FAILURE
%143 = call i32 @exit(i32 %142)
unreachable
144: ; preds = %136
store i64 0, i64* %9
br label %145
145: ; preds = %157, %144
%146 = load i64, i64* %9
%147 = load i64, i64* %10
%148 = load i64, i64* %11
%149 = sub nsw i64 %147, %148
%150 = sub nsw i64 %149, 1
%151 = icmp slt i64 %146, %150
br i1 %151, label %152, label %160
152: ; preds = %145
%153 = load i32*, i32** %4
%154 = call i32 @getline(i8** %14, i64* %16, i32* %153)
%155 = load i8*, i8** %14
%156 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %155)
br label %157
157: ; preds = %152
%158 = load i64, i64* %9
%159 = add nsw i64 %158, 1
store i64 %159, i64* %9
br label %145
160: ; preds = %145
store i64 0, i64* %9
br label %161
161: ; preds = %168, %160
%162 = load i64, i64* %9
%163 = load i64, i64* %8
%164 = icmp slt i64 %162, %163
br i1 %164, label %165, label %171
165: ; preds = %161
%166 = load i32*, i32** %4
%167 = call i32 @getline(i8** %14, i64* %16, i32* %166)
br label %168
168: ; preds = %165
%169 = load i64, i64* %9
%170 = add nsw i64 %169, 1
store i64 %170, i64* %9
br label %161
171: ; preds = %161
%172 = load i64, i64* %10
%173 = load i64, i64* %8
%174 = add nsw i64 %172, %173
%175 = sub nsw i64 %174, 1
store i64 %175, i64* %11
br label %181
176: ; preds = %42
%177 = load i32, i32* @stderr
%178 = call i32 @fprintf(i32 %177, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%179 = load i32, i32* @EXIT_FAILURE
%180 = call i32 @exit(i32 %179)
unreachable
181: ; preds = %171, %134, %107, %71
br label %17
182: ; preds = %17
br label %183
183: ; preds = %187, %182
%184 = load i32*, i32** %4
%185 = call i32 @getline(i8** %14, i64* %16, i32* %184)
%186 = icmp ne i32 %185, -1
br i1 %186, label %187, label %190
187: ; preds = %183
%188 = load i8*, i8** %14
%189 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %188)
br label %183
190: ; preds = %183
%191 = load i8*, i8** %13
%192 = call i32 @free(i8* %191)
%193 = load i8*, i8** %14
%194 = call i32 @free(i8* %193)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"%c %ld %ld\00"
@stderr = global i32 0
@.str.1 = [60 x i8] c"!!!!! instruction must be followed by a line number !!!!!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [35 x i8] c"!!!!! k must be increasing !!!!!\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [50 x i8] c"!!!!! k must be strictly increasing for = !!!!!\0A\00"
@.str.5 = [37 x i8] c"!!!!! m of D k m is missing !!!!!\0A\00"
@.str.6 = [36 x i8] c"!!!!! patchFile Format Error !!!!!\0A\00"
define i32 @applyPatch(i32* %0, i32* %1) {
%3 = alloca [100 x i8]
%4 = alloca i8
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%12 = bitcast i64* %5 to i8*
%13 = bitcast i64* %6 to i8*
%14 = bitcast i8** %7 to i8*
store i8* null, i8** %7
%15 = bitcast i8** %8 to i8*
store i8* null, i8** %8
%16 = bitcast i64* %9 to i8*
store i64 0, i64* %9
%17 = bitcast i64* %10 to i8*
store i64 0, i64* %10
%18 = call i32* @fgets(i8* %11, i32 100, i32* %0)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %140, %2
%21 = call i32 @getline(i8** %8, i64* %10, i32* %1)
%22 = icmp eq i32 %21, -1
br i1 %22, label %149, label %144
23: ; preds = %2, %140
%24 = phi i64 [ %141, %140 ], [ 0, %2 ]
%25 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %4, i64* %5, i64* %6)
%26 = icmp slt i32 %25, 2
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %23
%33 = load i64, i64* %5
%34 = icmp slt i64 %33, %24
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %32
%41 = load i8, i8* %4
%42 = sext i8 %41 to i32
switch i32 %42, label %135 [
i32 43, label %48
i32 61, label %68
i32 100, label %43
i32 68, label %104
]
43: ; preds = %40
%44 = sub i64 %33, %24
%45 = icmp sgt i64 %44, 0
br i1 %45, label %46, label %140
46: ; preds = %43
%47 = add nsw i64 %44, -1
br label %94
48: ; preds = %40
%49 = call i32 @getline(i8** %7, i64* %9, i32* %0)
%50 = load i64, i64* %5
%51 = icmp eq i64 %50, 0
br i1 %51, label %55, label %52
52: ; preds = %48
%53 = sub i64 %33, %24
%54 = icmp sgt i64 %53, 0
br i1 %54, label %58, label %65
55: ; preds = %48
%56 = load i8*, i8** %7
%57 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %56)
br label %140
58: ; preds = %52, %58
%59 = phi i64 [ %63, %58 ], [ 0, %52 ]
%60 = call i32 @getline(i8** %8, i64* %10, i32* %1)
%61 = load i8*, i8** %8
%62 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %61)
%63 = add nuw nsw i64 %59, 1
%64 = icmp eq i64 %63, %53
br i1 %64, label %65, label %58
65: ; preds = %58, %52
%66 = load i8*, i8** %7
%67 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %66)
br label %140
68: ; preds = %40
%69 = icmp sgt i64 %33, %24
br i1 %69, label %75, label %70
70: ; preds = %68
%71 = load i32, i32* @stderr
%72 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0))
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %68
%76 = call i32 @getline(i8** %7, i64* %9, i32* %0)
%77 = sub i64 %33, %24
%78 = icmp sgt i64 %77, 0
br i1 %78, label %79, label %91
79: ; preds = %75
%80 = add nsw i64 %77, -1
br label %81
81: ; preds = %79, %88
%82 = phi i64 [ 0, %79 ], [ %89, %88 ]
%83 = call i32 @getline(i8** %8, i64* %10, i32* %1)
%84 = icmp slt i64 %82, %80
br i1 %84, label %85, label %88
85: ; preds = %81
%86 = load i8*, i8** %8
%87 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %86)
br label %88
88: ; preds = %81, %85
%89 = add nuw nsw i64 %82, 1
%90 = icmp eq i64 %89, %77
br i1 %90, label %91, label %81
91: ; preds = %88, %75
%92 = load i8*, i8** %7
%93 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %92)
br label %140
94: ; preds = %46, %101
%95 = phi i64 [ 0, %46 ], [ %102, %101 ]
%96 = call i32 @getline(i8** %8, i64* %10, i32* %1)
%97 = icmp slt i64 %95, %47
br i1 %97, label %98, label %101
98: ; preds = %94
%99 = load i8*, i8** %8
%100 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %99)
br label %101
101: ; preds = %94, %98
%102 = add nuw nsw i64 %95, 1
%103 = icmp eq i64 %102, %44
br i1 %103, label %140, label %94
104: ; preds = %40
%105 = icmp ult i32 %25, 3
br i1 %105, label %110, label %106
106: ; preds = %104
%107 = xor i64 %24, -1
%108 = add i64 %33, %107
%109 = icmp sgt i64 %108, 0
br i1 %109, label %118, label %115
110: ; preds = %104
%111 = load i32, i32* @stderr
%112 = call i32 @fprintf(i32 %111, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%113 = load i32, i32* @EXIT_FAILURE
%114 = call i32 @exit(i32 %113)
unreachable
115: ; preds = %118, %106
%116 = load i64, i64* %6
%117 = icmp sgt i64 %116, 0
br i1 %117, label %125, label %131
118: ; preds = %106, %118
%119 = phi i64 [ %123, %118 ], [ 0, %106 ]
%120 = call i32 @getline(i8** %8, i64* %10, i32* %1)
%121 = load i8*, i8** %8
%122 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %121)
%123 = add nuw nsw i64 %119, 1
%124 = icmp eq i64 %123, %108
br i1 %124, label %115, label %118
125: ; preds = %115, %125
%126 = phi i64 [ %128, %125 ], [ 0, %115 ]
%127 = call i32 @getline(i8** %8, i64* %10, i32* %1)
%128 = add nuw nsw i64 %126, 1
%129 = load i64, i64* %6
%130 = icmp slt i64 %128, %129
br i1 %130, label %125, label %131
131: ; preds = %125, %115
%132 = phi i64 [ %116, %115 ], [ %129, %125 ]
%133 = add i64 %33, -1
%134 = add i64 %133, %132
br label %140
135: ; preds = %40
%136 = load i32, i32* @stderr
%137 = call i32 @fprintf(i32 %136, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%138 = load i32, i32* @EXIT_FAILURE
%139 = call i32 @exit(i32 %138)
unreachable
140: ; preds = %101, %43, %55, %65, %131, %91
%141 = phi i64 [ %134, %131 ], [ %33, %91 ], [ %33, %65 ], [ %33, %55 ], [ %33, %43 ], [ %33, %101 ]
%142 = call i32* @fgets(i8* %11, i32 100, i32* %0)
%143 = icmp eq i32* %142, null
br i1 %143, label %20, label %23
144: ; preds = %20, %144
%145 = load i8*, i8** %8
%146 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %145)
%147 = call i32 @getline(i8** %8, i64* %10, i32* %1)
%148 = icmp eq i32 %147, -1
br i1 %148, label %149, label %144
149: ; preds = %144, %20
%150 = load i8*, i8** %7
%151 = call i32 @free(i8* %150)
%152 = load i8*, i8** %8
%153 = call i32 @free(i8* %152)
ret i32 0
}