#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*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int get_int_line(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ write_keys(char, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  FILE *in_file, *out_file;
  int case_count, current_case;
  if (argc != 3) {
    printf("Usage: %s in_file out_file\n", argv[0]);
    return 1;
  }
  in_file = fopen(argv[1], "r");
  if (in_file == NULL) {
    printf("Could not open %s for reading.\n", argv[1]);
    return 1;
  }
  out_file = fopen(argv[2], "w");
  if (out_file == NULL) {
    printf("Could not open %s for writing.\n", argv[2]);
    fclose(in_file);
    return 1;
  }
  case_count = get_int_line(in_file);
  current_case = 1;
  while (current_case <= case_count) {
    fprintf(out_file, "Case #%i: ", current_case);
    char c;
    while (1) {
      c = fgetc(in_file);
      if (c == '\n' || c == '\0') {
        write_keys('\n', out_file);
        break;
      }
      write_keys(c, out_file);
    }
    fprintf(out_file, "\n");
    current_case++;
  }
  fclose(in_file);
  fclose(out_file);
  return 0;
}


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)
cmpl   $0x3,-0x8(%rbp)
je     11af <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f8 <main+0x188>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f2 <main+0x82>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe3d(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f8 <main+0x188>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    123e <main+0xce>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe1c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f8 <main+0x188>
mov    -0x18(%rbp),%rdi
call   1080 <get_int_line@plt>
mov    %eax,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     12df <main+0x16f>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xdf5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
cmp    $0xa,%eax
je     1298 <main+0x128>
movsbl -0x29(%rbp),%eax
cmp    $0x0,%eax
jne    12ab <main+0x13b>
mov    -0x20(%rbp),%rsi
mov    $0xa,%edi
call   1030 <write_keys@plt>
jmp    12bf <main+0x14f>
mov    -0x29(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1030 <write_keys@plt>
jmp    1272 <main+0x102>
mov    -0x20(%rbp),%rdi
lea    0xd72(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1251 <main+0xe1>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbp
cmp    $0x3,%edi
jne    124d <main+0xcd>
mov    0x8(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     126e <main+0xee>
mov    %rax,%r14
mov    0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     128c <main+0x10c>
mov    %rax,%rbx
mov    %r14,%rdi
call   1090 <get_int_line@plt>
test   %eax,%eax
jle    125a <main+0xda>
mov    %eax,%r12d
mov    $0x1,%ebp
lea    0xe75(%rip),%r15
jmp    1214 <main+0x94>
nopl   (%rax)
mov    $0xa,%edi
mov    %rbx,%rsi
call   1030 <write_keys@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
lea    0x1(%rbp),%eax
cmp    %r12d,%ebp
mov    %eax,%ebp
je     125a <main+0xda>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1060 <fgetc@plt>
cmp    $0xa,%al
je     11f0 <main+0x70>
test   %al,%al
je     11f0 <main+0x70>
movsbl %al,%edi
mov    %rbx,%rsi
call   1030 <write_keys@plt>
jmp    1230 <main+0xb0>
mov    0x0(%rbp),%rsi
lea    0xda8(%rip),%rdi
jmp    1279 <main+0xf9>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1283 <main+0x103>
mov    0x8(%rbp),%rsi
lea    0xda5(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rbp),%rsi
lea    0xda9(%rip),%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    127e <main+0xfe>

LLVM IR (-O0):
@.str = [28 x i8] c"Usage: %s in_file out_file\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [32 x i8] c"Could not open %s for reading.\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [32 x i8] c"Could not open %s for writing.\0A\00"
@.str.5 = [11 x i8] c"Case #%i: \00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 1, i32* %3
br label %82
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %6
%23 = load i32*, i32** %6
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %28)
store i32 1, i32* %3
br label %82
30: ; preds = %18
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %34, i32** %7
%35 = load i32*, i32** %7
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %44
37: ; preds = %30
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %40)
%42 = load i32*, i32** %6
%43 = call i32 @fclose(i32* %42)
store i32 1, i32* %3
br label %82
44: ; preds = %30
%45 = load i32*, i32** %6
%46 = call i32 @get_int_line(i32* %45)
store i32 %46, i32* %8
store i32 1, i32* %9
br label %47
47: ; preds = %72, %44
%48 = load i32, i32* %9
%49 = load i32, i32* %8
%50 = icmp sle i32 %48, %49
br i1 %50, label %51, label %77
51: ; preds = %47
%52 = load i32*, i32** %7
%53 = load i32, i32* %9
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %51, %68
%56 = load i32*, i32** %6
%57 = call signext i8 @fgetc(i32* %56)
store i8 %57, i8* %10
%58 = load i8, i8* %10
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 10
br i1 %60, label %65, label %61
61: ; preds = %55
%62 = load i8, i8* %10
%63 = sext i8 %62 to i32
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %61, %55
%66 = load i32*, i32** %7
%67 = call i32 @write_keys(i8 signext 10, i32* %66)
br label %72
68: ; preds = %61
%69 = load i8, i8* %10
%70 = load i32*, i32** %7
%71 = call i32 @write_keys(i8 signext %69, i32* %70)
br label %55
72: ; preds = %65
%73 = load i32*, i32** %7
%74 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%75 = load i32, i32* %9
%76 = add nsw i32 %75, 1
store i32 %76, i32* %9
br label %47
77: ; preds = %47
%78 = load i32*, i32** %6
%79 = call i32 @fclose(i32* %78)
%80 = load i32*, i32** %7
%81 = call i32 @fclose(i32* %80)
store i32 0, i32* %3
br label %82
82: ; preds = %77, %37, %25, %13
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
@.str = [28 x i8] c"Usage: %s in_file out_file\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [32 x i8] c"Could not open %s for reading.\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [32 x i8] c"Could not open %s for writing.\0A\00"
@.str.5 = [11 x i8] c"Case #%i: \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %42
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i8*, i8** %8
%14 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %42
15: ; preds = %7
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i8*, i8** %16
%22 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %21)
%23 = tail call i32 @fclose(i32* %10)
br label %42
24: ; preds = %15
%25 = tail call i32 @get_int_line(i32* %10)
%26 = icmp slt i32 %25, 1
br i1 %26, label %39, label %27
27: ; preds = %24, %32
%28 = phi i32 [ %35, %32 ], [ 1, %24 ]
%29 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %37, %27
%31 = tail call signext i8 @fgetc(i32* %10)
switch i8 %31, label %37 [
i8 10, label %32
i8 0, label %32
]
32: ; preds = %30, %30
%33 = tail call i32 @write_keys(i8 signext 10, i32* %18)
%34 = tail call i32 @fputc(i32 10, i32* %18)
%35 = add nuw i32 %28, 1
%36 = icmp eq i32 %28, %25
br i1 %36, label %39, label %27
37: ; preds = %30
%38 = tail call i32 @write_keys(i8 signext %31, i32* %18)
br label %30
39: ; preds = %32, %24
%40 = tail call i32 @fclose(i32* %10)
%41 = tail call i32 @fclose(i32* %18)
br label %42
42: ; preds = %39, %20, %12, %4
%43 = phi i32 [ 1, %4 ], [ 1, %12 ], [ 1, %20 ], [ 0, %39 ]
ret i32 %43
}