#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int sscanf(char *, char *, ...);
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  int lines;
  char fname[100];
  FILE *datafile;
  char buffer[300][200];
  int lineold;
  char inbuffer[200];
  int i;
  if (argc != 3)
    return -1;
  if (sscanf(argv[1], "%d", &lines) != 1)
    return -2;
  if ((lines <= 0) | (lines > 300))
    return -2;
  if (sscanf(argv[2], "%s", fname) != 1)
    return -3;
  datafile = fopen(fname, "r");
  lineold = 0;
  if (datafile != NULL) {
    do {
      if (fgets(buffer[lineold], 200, datafile) == NULL)
        break;
      lineold++;
    } while (lineold < lines);
    fclose(datafile);
  };
  fgets(inbuffer, 200, stdin);
  datafile = fopen(fname, "w");
  if (datafile == NULL)
    return -1;
  fprintf(datafile, "%s", inbuffer);
  for (i = 0; (i < lineold) && (i < lines - 1); i++)
    fprintf(datafile, "%s", buffer[i]);
  fclose(datafile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xebd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     117f <main+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ac <main+0x25c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe72(%rip),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     11ae <main+0x5e>
movl   $0xfffffffe,-0x4(%rbp)
jmp    13ac <main+0x25c>
cmpl   $0x0,-0x14(%rbp)
setle  %al
and    $0x1,%al
movzbl %al,%eax
cmpl   $0x12c,-0x14(%rbp)
setg   %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
cmp    $0x0,%eax
je     11e1 <main+0x91>
movl   $0xfffffffe,-0x4(%rbp)
jmp    13ac <main+0x25c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x80(%rbp),%rdx
lea    0xe0f(%rip),%rsi
mov    $0x0,%al
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     1210 <main+0xc0>
movl   $0xfffffffd,-0x4(%rbp)
jmp    13ac <main+0x25c>
lea    -0x80(%rbp),%rdi
lea    0xdeb(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x88(%rbp)
movl   $0x0,-0xeaf4(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     12a6 <main+0x156>
jmp    1244 <main+0xf4>
movslq -0xeaf4(%rbp),%rax
lea    -0xeaf0(%rbp),%rdi
imul   $0xc8,%rax,%rax
add    %rax,%rdi
mov    -0x88(%rbp),%rdx
mov    $0xc8,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    127c <main+0x12c>
jmp    129a <main+0x14a>
mov    -0xeaf4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xeaf4(%rbp)
mov    -0xeaf4(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     1244 <main+0xf4>
mov    -0x88(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0xebc0(%rbp),%rdi
mov    0x2d34(%rip),%rax
mov    (%rax),%rdx
mov    $0xc8,%esi
call   1040 <fgets@plt>
lea    -0x80(%rbp),%rdi
lea    0xd3c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    12f2 <main+0x1a2>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ac <main+0x25c>
mov    -0x88(%rbp),%rdi
lea    -0xebc0(%rbp),%rdx
lea    0xcfc(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0xebc4(%rbp)
mov    -0xebc4(%rbp),%ecx
xor    %eax,%eax
cmp    -0xeaf4(%rbp),%ecx
mov    %al,-0xebc5(%rbp)
jge    1347 <main+0x1f7>
mov    -0xebc4(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
setl   %al
mov    %al,-0xebc5(%rbp)
mov    -0xebc5(%rbp),%al
test   $0x1,%al
jne    135a <main+0x20a>
jmp    1399 <main+0x249>
mov    -0x88(%rbp),%rdi
movslq -0xebc4(%rbp),%rax
lea    -0xeaf0(%rbp),%rdx
imul   $0xc8,%rax,%rax
add    %rax,%rdx
lea    0xc83(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0xebc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xebc4(%rbp)
jmp    1316 <main+0x1c6>
mov    -0x88(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xebd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xebb8,%rsp
mov    $0xffffffff,%eax
cmp    $0x3,%edi
jne    12d7 <main+0x187>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe86(%rip),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1060 <sscanf@plt>
mov    %eax,%ecx
mov    $0xfffffffe,%eax
cmp    $0x1,%ecx
jne    12d7 <main+0x187>
mov    $0xfffffed3,%ecx
add    0xc(%rsp),%ecx
cmp    $0xfffffed4,%ecx
jb     12d7 <main+0x187>
mov    0x10(%rbx),%rdi
lea    0xe4d(%rip),%rsi
xor    %r15d,%r15d
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1060 <sscanf@plt>
mov    %eax,%ecx
mov    $0xfffffffd,%eax
cmp    $0x1,%ecx
jne    12d7 <main+0x187>
lea    0xe2a(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1232 <main+0xe2>
mov    %rax,%r14
lea    0x150(%rsp),%rbx
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0xc8,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     122a <main+0xda>
add    $0x1,%r15
movslq 0xc(%rsp),%rax
add    $0xc8,%rbx
cmp    %rax,%r15
jl     1200 <main+0xb0>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%rdx
lea    0x80(%rsp),%rdi
mov    $0xc8,%esi
call   1050 <fgets@plt>
lea    0xdb3(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    $0xffffffff,%eax
test   %r14,%r14
je     12d7 <main+0x187>
lea    0x80(%rsp),%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
test   %r15d,%r15d
jle    12cd <main+0x17d>
cmpl   $0x2,0xc(%rsp)
jl     12cd <main+0x17d>
mov    %r15d,%r15d
lea    0x150(%rsp),%rbx
mov    $0x1,%r12d
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
cmp    %r15,%r12
jae    12cd <main+0x17d>
movslq 0xc(%rsp),%rax
add    $0xffffffffffffffff,%rax
add    $0xc8,%rbx
lea    0x1(%r12),%rcx
cmp    %rax,%r12
mov    %rcx,%r12
jl     12a0 <main+0x150>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xebb8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@stdin = global i32* null
@.str.3 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [100 x i8]
%8 = alloca i32*
%9 = alloca [300 x [200 x i8]]
%10 = alloca i32
%11 = alloca [200 x i8]
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %103
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 (i8*, i8*, ...) @sscanf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %16
store i32 -2, i32* %3
br label %103
23: ; preds = %16
%24 = load i32, i32* %6
%25 = icmp sle i32 %24, 0
%26 = zext i1 %25 to i32
%27 = load i32, i32* %6
%28 = icmp sgt i32 %27, 300
%29 = zext i1 %28 to i32
%30 = or i32 %26, %29
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %23
store i32 -2, i32* %3
br label %103
33: ; preds = %23
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%38 = call i32 (i8*, i8*, ...) @sscanf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = icmp ne i32 %38, 1
br i1 %39, label %40, label %41
40: ; preds = %33
store i32 -3, i32* %3
br label %103
41: ; preds = %33
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %43, i32** %8
store i32 0, i32* %10
%44 = load i32*, i32** %8
%45 = icmp ne i32* %44, null
br i1 %45, label %46, label %66
46: ; preds = %41
br label %47
47: ; preds = %59, %46
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [300 x [200 x i8]], [300 x [200 x i8]]* %9, i64 0, i64 %49
%51 = getelementptr inbounds [200 x i8], [200 x i8]* %50, i64 0, i64 0
%52 = load i32*, i32** %8
%53 = call i32* @fgets(i8* %51, i32 200, i32* %52)
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %56
55: ; preds = %47
br label %63
56: ; preds = %47
%57 = load i32, i32* %10
%58 = add nsw i32 %57, 1
store i32 %58, i32* %10
br label %59
59: ; preds = %56
%60 = load i32, i32* %10
%61 = load i32, i32* %6
%62 = icmp slt i32 %60, %61
br i1 %62, label %47, label %63
63: ; preds = %59, %55
%64 = load i32*, i32** %8
%65 = call i32 @fclose(i32* %64)
br label %66
66: ; preds = %63, %41
%67 = getelementptr inbounds [200 x i8], [200 x i8]* %11, i64 0, i64 0
%68 = load i32*, i32** @stdin
%69 = call i32* @fgets(i8* %67, i32 200, i32* %68)
%70 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%71 = call i32* @fopen(i8* %70, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %71, i32** %8
%72 = load i32*, i32** %8
%73 = icmp eq i32* %72, null
br i1 %73, label %74, label %75
74: ; preds = %66
store i32 -1, i32* %3
br label %103
75: ; preds = %66
%76 = load i32*, i32** %8
%77 = getelementptr inbounds [200 x i8], [200 x i8]* %11, i64 0, i64 0
%78 = call i32 @fprintf(i32* %76, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %77)
store i32 0, i32* %12
br label %79
79: ; preds = %97, %75
%80 = load i32, i32* %12
%81 = load i32, i32* %10
%82 = icmp slt i32 %80, %81
br i1 %82, label %83, label %88
83: ; preds = %79
%84 = load i32, i32* %12
%85 = load i32, i32* %6
%86 = sub nsw i32 %85, 1
%87 = icmp slt i32 %84, %86
br label %88
88: ; preds = %83, %79
%89 = phi i1 [ false, %79 ], [ %87, %83 ]
br i1 %89, label %90, label %100
90: ; preds = %88
%91 = load i32*, i32** %8
%92 = load i32, i32* %12
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [300 x [200 x i8]], [300 x [200 x i8]]* %9, i64 0, i64 %93
%95 = getelementptr inbounds [200 x i8], [200 x i8]* %94, i64 0, i64 0
%96 = call i32 @fprintf(i32* %91, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %95)
br label %97
97: ; preds = %90
%98 = load i32, i32* %12
%99 = add nsw i32 %98, 1
store i32 %99, i32* %12
br label %79
100: ; preds = %88
%101 = load i32*, i32** %8
%102 = call i32 @fclose(i32* %101)
store i32 0, i32* %3
br label %103
103: ; preds = %100, %74, %40, %32, %22, %15
%104 = load i32, i32* %3
ret i32 %104
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@stdin = global i32* null
@.str.3 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = alloca [300 x [200 x i8]]
%6 = alloca [200 x i8]
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [300 x [200 x i8]], [300 x [200 x i8]]* %5, i64 0, i64 0, i64 0
%10 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%11 = icmp eq i32 %0, 3
br i1 %11, label %12, label %70
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 (i8*, i8*, ...) @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %70
17: ; preds = %12
%18 = load i32, i32* %3
%19 = add i32 %18, -301
%20 = icmp ult i32 %19, -300
br i1 %20, label %70, label %21
21: ; preds = %17
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = call i32 (i8*, i8*, ...) @sscanf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %70
26: ; preds = %21
%27 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %43, label %29
29: ; preds = %26, %34
%30 = phi i64 [ %35, %34 ], [ 0, %26 ]
%31 = getelementptr inbounds [300 x [200 x i8]], [300 x [200 x i8]]* %5, i64 0, i64 %30, i64 0
%32 = call i32* @fgets(i8* %31, i32 200, i32* %27)
%33 = icmp eq i32* %32, null
br i1 %33, label %39, label %34
34: ; preds = %29
%35 = add nuw nsw i64 %30, 1
%36 = load i32, i32* %3
%37 = sext i32 %36 to i64
%38 = icmp slt i64 %35, %37
br i1 %38, label %29, label %39
39: ; preds = %29, %34
%40 = phi i64 [ %30, %29 ], [ %35, %34 ]
%41 = trunc i64 %40 to i32
%42 = call i32 @fclose(i32* %27)
br label %43
43: ; preds = %39, %26
%44 = phi i32 [ %41, %39 ], [ 0, %26 ]
%45 = load i32*, i32** @stdin
%46 = call i32* @fgets(i8* %10, i32 200, i32* %45)
%47 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%48 = icmp eq i32* %47, null
br i1 %48, label %70, label %49
49: ; preds = %43
%50 = call i32 @fputs(i8* %10, i32* %47)
%51 = icmp sgt i32 %44, 0
%52 = load i32, i32* %3
%53 = icmp sgt i32 %52, 1
%54 = select i1 %51, i1 %53, i1 false
br i1 %54, label %55, label %68
55: ; preds = %49
%56 = zext i32 %44 to i64
br label %57
57: ; preds = %55, %57
%58 = phi i64 [ 0, %55 ], [ %61, %57 ]
%59 = getelementptr inbounds [300 x [200 x i8]], [300 x [200 x i8]]* %5, i64 0, i64 %58, i64 0
%60 = call i32 @fputs(i8* %59, i32* %47)
%61 = add nuw nsw i64 %58, 1
%62 = icmp ult i64 %61, %56
%63 = load i32, i32* %3
%64 = add nsw i32 %63, -1
%65 = sext i32 %64 to i64
%66 = icmp slt i64 %61, %65
%67 = select i1 %62, i1 %66, i1 false
br i1 %67, label %57, label %68
68: ; preds = %57, %49
%69 = call i32 @fclose(i32* %47)
br label %70
70: ; preds = %43, %21, %17, %12, %2, %68
%71 = phi i32 [ 0, %68 ], [ -1, %2 ], [ -2, %12 ], [ -2, %17 ], [ -3, %21 ], [ -1, %43 ]
ret i32 %71
}