#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main(int argc, char **argv) {
  FILE *fp;
  char buf[1024];
  int len;
  if (argc < 2) {
    printf("Usage: %s file\n", argv[0]);
    return 0;
  }
  fp = fopen(argv[1], "r");
  if (fp == NULL) {
    printf("Error opening %s", argv[1]);
    return 1;
  }
  printf("char *lisp_functions[] = {\n");
  while (fgets(buf, 1024, fp) != NULL) {
    len = strlen(buf);
    if (buf[len - 1] == '\n')
      buf[len - 1] = '\0';
    printf("\"%s\\n\",\n", buf);
  }
  printf("\"\\n\"\n};\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1184 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1266 <main+0x126>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c9 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1266 <main+0x126>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1251 <main+0x111>
lea    -0x420(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x424(%rbp)
mov    -0x424(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1237 <main+0xf7>
mov    -0x424(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rsi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d7 <main+0x97>
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     117c <main+0x2c>
mov    (%rbx),%rsi
lea    0xe92(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1231 <main+0xe1>
mov    0x8(%rbx),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     121a <main+0xca>
mov    %rax,%r14
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     120a <main+0xba>
lea    0xe60(%rip),%r15
jmp    11f2 <main+0xa2>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     120a <main+0xba>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    11d0 <main+0x80>
movb   $0x0,-0x1(%rsp,%rax,1)
jmp    11d0 <main+0x80>
lea    0xe36(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    1231 <main+0xe1>
mov    0x8(%rbx),%rsi
lea    0xded(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Usage: %s file\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"Error opening %s\00"
@.str.3 = [28 x i8] c"char *lisp_functions[] = {\0A\00"
@.str.4 = [9 x i8] c"\22%s\\n\22,\0A\00"
@.str.5 = [9 x i8] c"\22\\n\22\0A};\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [1024 x i8]
%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 %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 0, i32* %3
br label %55
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %28
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %26)
store i32 1, i32* %3
br label %55
28: ; preds = %16
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %50, %28
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%32 = load i32*, i32** %6
%33 = call i32* @fgets(i8* %31, i32 1024, i32* %32)
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %53
35: ; preds = %30
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%37 = call i32 @strlen(i8* %36)
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 10
br i1 %44, label %45, label %50
45: ; preds = %35
%46 = load i32, i32* %8
%47 = sub nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %48
store i8 0, i8* %49
br label %50
50: ; preds = %45, %35
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %51)
br label %30
53: ; preds = %30
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %55
55: ; preds = %53, %23, %11
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [16 x i8] c"Usage: %s file\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"Error opening %s\00"
@.str.4 = [9 x i8] c"\22%s\\n\22,\0A\00"
@str = [27 x i8] c"char *lisp_functions[] = {\00"
@str.6 = [8 x i8] c"\22\\n\22\0A};\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %35
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%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 %14, label %17
14: ; preds = %9
%15 = load i8*, i8** %10
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %35
17: ; preds = %9
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%19 = call i32* @fgets(i8* %4, i32 1024, i32* %12)
%20 = icmp eq i32* %19, null
br i1 %20, label %33, label %21
21: ; preds = %17, %29
%22 = call i32 @strlen(i8* %4)
%23 = add nsw i32 %22, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 10
br i1 %27, label %28, label %29
28: ; preds = %21
store i8 0, i8* %25
br label %29
29: ; preds = %28, %21
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%31 = call i32* @fgets(i8* %4, i32 1024, i32* %12)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %21
33: ; preds = %29, %17
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0))
br label %35
35: ; preds = %33, %14, %6
%36 = phi i32 [ 0, %6 ], [ 1, %14 ], [ 0, %33 ]
ret i32 %36
}