#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 */
char *escape(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strncmp(char *, char *, int);
int usage(char *);
int main(int argc, char *argv[]) {
  char *func_name = argv[1];
  FILE *in = fopen(argv[2], "r");
  if (func_name == NULL || in == NULL)
    return usage(argv[0]);
  char *line = NULL;
  size_t len = 0;
  printf("void %s(FILE *out)\n", func_name);
  printf("{\n");
  printf("  fputs(\n");
  while (getline(&line, &len, in) != -1) {
    if (strncmp(line, "//", 2) == 0)
      continue;
    char *l = escape(line);
    printf("    \"%s\\n\"\n", l);
    free(l);
  }
  free(line);
  fclose(in);
  printf("    , out);\n");
  printf("}\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe4f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d0 <main+0x50>
cmpq   $0x0,-0x20(%rbp)
jne    11e4 <main+0x64>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    12bb <main+0x13b>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     128d <main+0x10d>
mov    -0x28(%rbp),%rdi
lea    0xddc(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1260 <main+0xe0>
jmp    1222 <main+0xa2>
mov    -0x28(%rbp),%rdi
call   10a0 <escape@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    1222 <main+0xa2>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xd8c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rdi
lea    0xe50(%rip),%rsi
call   1090 <fopen@plt>
test   %r14,%r14
je     128e <main+0xfe>
mov    %rax,%rbx
test   %rax,%rax
je     128e <main+0xfe>
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe1f(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe31(%rip),%rdi
call   1050 <puts@plt>
lea    0xe27(%rip),%rdi
call   1050 <puts@plt>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   10a0 <getline@plt>
cmp    $0xffffffff,%eax
je     12a4 <main+0x114>
lea    0xdef(%rip),%r14
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xde1(%rip),%r13
jmp    1253 <main+0xc3>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10a0 <getline@plt>
cmp    $0xffffffff,%eax
je     12a4 <main+0x114>
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1240 <main+0xb0>
mov    0x8(%rsp),%rdi
call   10b0 <escape@plt>
mov    %rax,%rbp
mov    %r13,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
jmp    1240 <main+0xb0>
mov    (%r15),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <usage@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
lea    0xd73(%rip),%rdi
call   1050 <puts@plt>
lea    0xd73(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [20 x i8] c"void %s(FILE *out)\0A\00"
@.str.2 = [3 x i8] c"{\0A\00"
@.str.3 = [10 x i8] c" fputs(\0A\00"
@.str.4 = [3 x i8] c"//\00"
@.str.5 = [12 x i8] c" \22%s\\n\22\0A\00"
@.str.6 = [13 x i8] c" , out);\0A\00"
@.str.7 = [3 x i8] c"}\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %6
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %7
%18 = load i8*, i8** %6
%19 = icmp eq i8* %18, null
br i1 %19, label %23, label %20
20: ; preds = %2
%21 = load i32*, i32** %7
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %28
23: ; preds = %20, %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @usage(i8* %26)
store i32 %27, i32* %3
br label %56
28: ; preds = %20
store i8* null, i8** %8
store i64 0, i64* %9
%29 = load i8*, i8** %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %42, %41, %28
%34 = load i32*, i32** %7
%35 = call i32 @getline(i8** %8, i64* %9, i32* %34)
%36 = icmp ne i32 %35, -1
br i1 %36, label %37, label %49
37: ; preds = %33
%38 = load i8*, i8** %8
%39 = call i64 @strncmp(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
br label %33
42: ; preds = %37
%43 = load i8*, i8** %8
%44 = call i8* @escape(i8* %43)
store i8* %44, i8** %10
%45 = load i8*, i8** %10
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %45)
%47 = load i8*, i8** %10
%48 = call i32 @free(i8* %47)
br label %33
49: ; preds = %33
%50 = load i8*, i8** %8
%51 = call i32 @free(i8* %50)
%52 = load i32*, i32** %7
%53 = call i32 @fclose(i32* %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %56
56: ; preds = %49, %23
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [20 x i8] c"void %s(FILE *out)\0A\00"
@.str.4 = [3 x i8] c"//\00"
@.str.5 = [12 x i8] c" \22%s\\n\22\0A\00"
@str = [2 x i8] c"{\00"
@str.8 = [9 x i8] c" fputs(\00"
@str.9 = [12 x i8] c" , out);\00"
@str.10 = [2 x i8] c"}\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %6, null
%11 = icmp eq i32* %9, null
%12 = or i1 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %1
%15 = tail call i32 @usage(i8* %14)
br label %42
16: ; preds = %2
%17 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%18 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.8, i64 0, i64 0))
%22 = call i32 @getline(i8** %3, i64* %4, i32* %9)
%23 = icmp eq i32 %22, -1
br i1 %23, label %36, label %24
24: ; preds = %16, %33
%25 = load i8*, i8** %3
%26 = call i64 @strncmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%27 = icmp eq i64 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %24
%29 = load i8*, i8** %3
%30 = call i8* @escape(i8* %29)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %30)
%32 = call i32 @free(i8* %30)
br label %33
33: ; preds = %28, %24
%34 = call i32 @getline(i8** %3, i64* %4, i32* %9)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %24
36: ; preds = %33, %16
%37 = load i8*, i8** %3
%38 = call i32 @free(i8* %37)
%39 = call i32 @fclose(i32* %9)
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.9, i64 0, i64 0))
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.10, i64 0, i64 0))
br label %42
42: ; preds = %36, %13
%43 = phi i32 [ %15, %13 ], [ 0, %36 ]
ret i32 %43
}