#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 EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char **argv) {
  if (argc < 3) {
    printf("Usage: literate -[s|d] <input>\n");
    printf("  Ex.: literate -s main.lc > main.c\n");
    printf("  Ex.: literate -d main.lc > main.md\n");
    exit(EXIT_FAILURE);
  }
  const char *input_path = argv[2];
  const int should_print_code = (strncmp(argv[1], "-s", 2) == 0) ? 1 : 0;
  FILE *fp = fopen(input_path, "r");
  if (fp == NULL) {
    perror("Fatal: Unable to open input file.\n");
    exit(EXIT_FAILURE);
  }
  int last_char_was_newline = 0;
  int in_code = 0;
  int in_desired_block = 0;
  char ch = ' ';
  while ((ch = (char)fgetc(fp)) != EOF) {
    in_desired_block = (!should_print_code || (in_code == should_print_code));
    if (ch == '\n') {
      last_char_was_newline = 1;
      in_code = 0;
      if (in_desired_block) {
        printf("%c", ch);
      }
      continue;
    } else if (last_char_was_newline && ch == '>') {
      in_code = 1;
      if (in_desired_block)
        printf("    ");
      continue;
    } else if (last_char_was_newline && ch == ' ') {
      last_char_was_newline = 0;
      continue;
    }
    last_char_was_newline = 0;
    if (in_desired_block)
      printf("%c", ch);
  }
  fclose(fp);
  return EXIT_SUCCESS;
}


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)
cmpl   $0x3,-0x8(%rbp)
jge    11c8 <main+0x58>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe88(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    123a <main+0xca>
lea    0xe49(%rip),%rdi
call   1080 <perror@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movb   $0x20,-0x35(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x35(%rbp)
movsbl %al,%eax
mov    0x2d7f(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1366 <main+0x1f6>
mov    $0x1,%al
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x36(%rbp)
je     128f <main+0x11f>
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
sete   %al
mov    %al,-0x36(%rbp)
mov    -0x36(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x34(%rbp)
movsbl -0x35(%rbp),%eax
cmp    $0xa,%eax
jne    12d6 <main+0x166>
movl   $0x1,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     12d1 <main+0x161>
movsbl -0x35(%rbp),%esi
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1253 <main+0xe3>
cmpl   $0x0,-0x2c(%rbp)
je     1311 <main+0x1a1>
movsbl -0x35(%rbp),%eax
cmp    $0x3e,%eax
jne    1311 <main+0x1a1>
movl   $0x1,-0x30(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     130c <main+0x19c>
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1253 <main+0xe3>
cmpl   $0x0,-0x2c(%rbp)
je     1334 <main+0x1c4>
movsbl -0x35(%rbp),%eax
cmp    $0x20,%eax
jne    1334 <main+0x1c4>
movl   $0x0,-0x2c(%rbp)
jmp    1253 <main+0xe3>
jmp    1339 <main+0x1c9>
jmp    133e <main+0x1ce>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1361 <main+0x1f1>
movsbl -0x35(%rbp),%esi
lea    0xd39(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1253 <main+0xe3>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2c5a(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jle    1302 <main+0x172>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rbx
lea    0xe4d(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
mov    %rax,%r14
movl   $0x0,0x4(%rsp)
test   %rax,%rax
sete   %r15b
lea    0xe2d(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1328 <main+0x198>
mov    %rax,%rbp
mov    %rax,%rdi
call   1080 <fgetc@plt>
movsbl %al,%edi
mov    0x2dec(%rip),%r13
movsbl 0x0(%r13),%ecx
cmp    %ecx,%edi
jne    1225 <main+0x95>
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x4(%rsp),%ecx
mov    %r15b,%cl
mov    %ecx,0x4(%rsp)
shl    $0x18,%eax
xor    %r15d,%r15d
xor    %ecx,%ecx
jmp    1259 <main+0xc9>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1080 <fgetc@plt>
movsbl %al,%edi
shl    $0x18,%eax
movsbl 0x0(%r13),%edx
mov    $0x1,%cl
cmp    %edx,%edi
je     1205 <main+0x75>
test   %r14,%r14
sete   %dl
cmp    0x4(%rsp),%r15d
setne  %r12b
and    %dl,%r12b
jmp    128d <main+0xfd>
nopl   (%rax)
mov    %rbp,%rdi
call   1080 <fgetc@plt>
movsbl %al,%edi
shl    $0x18,%eax
movsbl 0x0(%r13),%edx
xor    %ecx,%ecx
cmp    %edx,%edi
je     1205 <main+0x75>
cmp    $0xa000000,%eax
je     12c0 <main+0x130>
cmp    $0x3e000000,%eax
setne  %dl
mov    %ecx,%ebx
not    %bl
or     %dl,%bl
test   $0x1,%bl
je     12e0 <main+0x150>
cmp    $0x20000000,%eax
sete   %al
and    %al,%cl
or     %r12b,%cl
jne    1270 <main+0xe0>
call   1030 <putchar@plt>
jmp    1270 <main+0xe0>
nopl   (%rax)
xor    %r15d,%r15d
test   %r12b,%r12b
jne    1240 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1240 <main+0xb0>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%r15d
test   %r12b,%r12b
jne    1240 <main+0xb0>
lea    0xd32(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1240 <main+0xb0>
lea    0xd24(%rip),%rdi
call   1050 <puts@plt>
lea    0xd37(%rip),%rdi
call   1050 <puts@plt>
lea    0xd4f(%rip),%rdi
call   1050 <puts@plt>
jmp    1334 <main+0x1a4>
lea    0xcd6(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c9d(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

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

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"-s\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [35 x i8] c"Fatal: Unable to open input file.\0A\00"
@EOF = global i8 0
@.str.7 = [5 x i8] c" \00"
@EXIT_SUCCESS = global i32 0
@str = [31 x i8] c"Usage: literate -[s|d] <input>\00"
@str.8 = [36 x i8] c" Ex.: literate -s main.lc > main.c\00"
@str.9 = [37 x i8] c" Ex.: literate -d main.lc > main.md\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.8, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.9, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i32
%18 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %28, label %20
20: ; preds = %10
%21 = tail call i64 @fgetc(i32* %18)
%22 = trunc i64 %21 to i32
%23 = shl i32 %22, 24
%24 = ashr exact i32 %23, 24
%25 = load i8, i8* @EOF
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %24, %26
br i1 %27, label %76, label %55
28: ; preds = %10
%29 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @exit(i32 %30)
unreachable
32: ; preds = %55, %68
%33 = phi i32 [ %56, %55 ], [ %72, %68 ]
%34 = phi i32 [ %57, %55 ], [ %71, %68 ]
%35 = phi i1 [ %59, %55 ], [ false, %68 ]
%36 = icmp eq i32 %34, 167772160
br i1 %36, label %37, label %40
37: ; preds = %32
br i1 %61, label %46, label %38
38: ; preds = %37
%39 = tail call i32 @putchar(i32 10)
br label %46
40: ; preds = %32
%41 = icmp eq i32 %34, 1040187392
%42 = and i1 %35, %41
br i1 %42, label %43, label %62
43: ; preds = %40
br i1 %61, label %46, label %44
44: ; preds = %43
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %46
46: ; preds = %43, %44, %37, %38
%47 = phi i32 [ 0, %38 ], [ 0, %37 ], [ 1, %44 ], [ 1, %43 ]
%48 = tail call i64 @fgetc(i32* %18)
%49 = trunc i64 %48 to i32
%50 = shl i32 %49, 24
%51 = ashr exact i32 %50, 24
%52 = load i8, i8* @EOF
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %51, %53
br i1 %54, label %76, label %55
55: ; preds = %20, %46
%56 = phi i32 [ %51, %46 ], [ %24, %20 ]
%57 = phi i32 [ %50, %46 ], [ %23, %20 ]
%58 = phi i32 [ %47, %46 ], [ 0, %20 ]
%59 = phi i1 [ true, %46 ], [ false, %20 ]
%60 = icmp ne i32 %58, %17
%61 = and i1 %16, %60
br label %32
62: ; preds = %40
%63 = icmp eq i32 %34, 536870912
%64 = and i1 %35, %63
%65 = select i1 %64, i1 true, i1 %61
br i1 %65, label %68, label %66
66: ; preds = %62
%67 = tail call i32 @putchar(i32 %33)
br label %68
68: ; preds = %62, %66
%69 = tail call i64 @fgetc(i32* %18)
%70 = trunc i64 %69 to i32
%71 = shl i32 %70, 24
%72 = ashr exact i32 %71, 24
%73 = load i8, i8* @EOF
%74 = sext i8 %73 to i32
%75 = icmp eq i32 %72, %74
br i1 %75, label %76, label %32
76: ; preds = %46, %68, %20
%77 = tail call i32 @fclose(i32* %18)
%78 = load i32, i32* @EXIT_SUCCESS
ret i32 %78
}