#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
char toupper(int);
int main(int argc, char *argv[]) {
  FILE *in, *out;
  int ch;
  if (argc < 2)
    return 1;
  if (NULL == (in = fopen(argv[1], "r")))
    return 1;
  if (NULL == (out = fopen(argv[2], "w")))
    return 1;
  fprintf(out, "/* a silly file, generated from %s */\n\n", argv[1]);
  fprintf(out, "const char *generated_string = \"");
  putc('"', in);
  while (EOF != (ch = getc(in))) {
    if ('\n' == ch)
      putc('\\', out);
    putc(toupper(ch), out);
  }
  fprintf(out, "\";\n");
  fclose(out);
  fclose(in);
  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   $0x2,-0x8(%rbp)
jge    118c <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    12af <main+0x14f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe65(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11be <main+0x5e>
movl   $0x1,-0x4(%rbp)
jmp    12af <main+0x14f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe35(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11f0 <main+0x90>
movl   $0x1,-0x4(%rbp)
jmp    12af <main+0x14f>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe01(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rsi
mov    $0x22,%edi
call   1050 <putc@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
mov    %ecx,-0x24(%rbp)
cmp    %ecx,%eax
je     1284 <main+0x124>
mov    $0xa,%eax
cmp    -0x24(%rbp),%eax
jne    126b <main+0x10b>
mov    -0x20(%rbp),%rsi
mov    $0x5c,%edi
call   1050 <putc@plt>
mov    -0x24(%rbp),%edi
call   1030 <toupper@plt>
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1050 <putc@plt>
jmp    122a <main+0xca>
mov    -0x20(%rbp),%rdi
lea    0xdbe(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%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   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%r14d
cmp    $0x2,%edi
jl     1243 <main+0xd3>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe68(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1243 <main+0xd3>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
lea    0xe4e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1243 <main+0xd3>
mov    %rax,%r13
mov    0x8(%rbx),%rdx
lea    0xe34(%rip),%rsi
xor    %r14d,%r14d
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe48(%rip),%rdi
mov    $0x20,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1080 <fwrite@plt>
mov    $0x22,%edi
mov    %r15,%rsi
call   1050 <putc@plt>
mov    0x2dde(%rip),%r12
mov    (%r12),%ebp
mov    %r15,%rdi
call   1090 <getc@plt>
cmp    %eax,%ebp
jne    1255 <main+0xe5>
lea    0xe2c(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1080 <fwrite@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
jmp    1284 <main+0x114>
nopl   0x0(%rax)
mov    %ebx,%edi
call   1030 <toupper@plt>
movsbl %al,%edi
mov    %r13,%rsi
call   1050 <putc@plt>
mov    (%r12),%ebp
mov    %r15,%rdi
call   1090 <getc@plt>
mov    %eax,%ebx
cmp    %eax,%ebp
je     121a <main+0xaa>
cmp    $0xa,%ebx
jne    1260 <main+0xf0>
mov    $0x5c,%edi
mov    %r13,%rsi
call   1050 <putc@plt>
jmp    1260 <main+0xf0>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [40 x i8] c"/* a silly file, generated from %s */\0A\0A\00"
@.str.3 = [33 x i8] c"const char *generated_string = \22\00"
@EOF = global i32 0
@.str.4 = [4 x i8] c"\22;\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 1, i32* %3
br label %59
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %6
%17 = icmp eq i32* null, %16
br i1 %17, label %18, label %19
18: ; preds = %12
store i32 1, i32* %3
br label %59
19: ; preds = %12
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %7
%24 = icmp eq i32* null, %23
br i1 %24, label %25, label %26
25: ; preds = %19
store i32 1, i32* %3
br label %59
26: ; preds = %19
%27 = load i32*, i32** %7
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = load i32*, i32** %7
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32*, i32** %6
%35 = call i32 @putc(i8 signext 34, i32* %34)
br label %36
36: ; preds = %47, %26
%37 = load i32, i32* @EOF
%38 = load i32*, i32** %6
%39 = call i32 @getc(i32* %38)
store i32 %39, i32* %8
%40 = icmp ne i32 %37, %39
br i1 %40, label %41, label %52
41: ; preds = %36
%42 = load i32, i32* %8
%43 = icmp eq i32 10, %42
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i32*, i32** %7
%46 = call i32 @putc(i8 signext 92, i32* %45)
br label %47
47: ; preds = %44, %41
%48 = load i32, i32* %8
%49 = call signext i8 @toupper(i32 %48)
%50 = load i32*, i32** %7
%51 = call i32 @putc(i8 signext %49, i32* %50)
br label %36
52: ; preds = %36
%53 = load i32*, i32** %7
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%55 = load i32*, i32** %7
%56 = call i32 @fclose(i32* %55)
%57 = load i32*, i32** %6
%58 = call i32 @fclose(i32* %57)
store i32 0, i32* %3
br label %59
59: ; preds = %52, %25, %18, %11
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [40 x i8] c"/* a silly file, generated from %s */\0A\0A\00"
@.str.3 = [33 x i8] c"const char *generated_string = \22\00"
@EOF = global i32 0
@.str.4 = [4 x i8] c"\22;\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %37, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %37, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %37, label %14
14: ; preds = %9
%15 = load i8*, i8** %5
%16 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i64 32, i64 1, i32* %12)
%18 = tail call i32 @putc(i8 signext 34, i32* %7)
%19 = load i32, i32* @EOF
%20 = tail call i32 @getc(i32* %7)
%21 = icmp eq i32 %19, %20
br i1 %21, label %33, label %22
22: ; preds = %14, %27
%23 = phi i32 [ %31, %27 ], [ %20, %14 ]
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i32 @putc(i8 signext 92, i32* %12)
br label %27
27: ; preds = %25, %22
%28 = tail call signext i8 @toupper(i32 %23)
%29 = tail call i32 @putc(i8 signext %28, i32* %12)
%30 = load i32, i32* @EOF
%31 = tail call i32 @getc(i32* %7)
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %22
33: ; preds = %27, %14
%34 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 3, i64 1, i32* %12)
%35 = tail call i32 @fclose(i32* %12)
%36 = tail call i32 @fclose(i32* %7)
br label %37
37: ; preds = %9, %4, %2, %33
%38 = phi i32 [ 0, %33 ], [ 1, %2 ], [ 1, %4 ], [ 1, %9 ]
ret i32 %38
}