#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ isascii(char);
scalar_t__ isprint(char);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  char *buffer;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s identifier < filename.txt > filename.h\n",
            argv[0]);
    exit(1);
  }
  printf("static const char %s[] =", argv[1]);
  buffer = malloc(1048576);
  for (;;) {
    char *p;
    p = fgets(buffer, 1048576, stdin);
    if (p == NULL)
      break;
    printf(" \\\n    \"");
    while (*p) {
      if (*p == '"') {
        printf("\\\"");
      } else if (*p == '\\') {
        printf("\\\\");
      } else if (*p == '\r') {
        printf("\\r");
      } else if (*p == '\n') {
        printf("\\n");
      } else if (isascii(*p) && isprint(*p)) {
        putchar(*p);
      } else {
        printf("\\0%o", *p);
      }
      p++;
    }
    printf("\"");
  }
  printf(";\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c6 <main+0x46>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x100000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2df3(%rip),%rax
mov    (%rax),%edx
mov    $0x100000,%esi
call   1050 <fgets@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1215 <main+0x95>
jmp    1346 <main+0x1c6>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1333 <main+0x1b3>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    1253 <main+0xd3>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1322 <main+0x1a2>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    1276 <main+0xf6>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    131d <main+0x19d>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    1299 <main+0x119>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1318 <main+0x198>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    12bc <main+0x13c>
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1313 <main+0x193>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   10a0 <isascii@plt>
cmp    $0x0,%rax
je     12f9 <main+0x179>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1080 <isprint@plt>
cmp    $0x0,%rax
je     12f9 <main+0x179>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
jmp    130e <main+0x18e>
mov    -0x20(%rbp),%rax
movsbl (%rax),%esi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1313 <main+0x193>
jmp    1318 <main+0x198>
jmp    131d <main+0x19d>
jmp    1322 <main+0x1a2>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1223 <main+0xa3>
lea    0xd18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ea <main+0x6a>
lea    0xd18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%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
jne    12f9 <main+0x169>
mov    0x8(%rsi),%rsi
lea    0xf0f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x100000,%edi
call   1080 <malloc@plt>
mov    0x2e21(%rip),%rcx
mov    (%rcx),%edx
mov    %rax,(%rsp)
mov    %rax,%rdi
mov    $0x100000,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     12dc <main+0x14c>
mov    %rax,%rbx
lea    0xef6(%rip),%r13
lea    0xe0c(%rip),%r12
lea    0xeee(%rip),%rbp
lea    0xee4(%rip),%r14
lea    0xed7(%rip),%r15
jmp    123d <main+0xad>
nopl   0x0(%rax,%rax,1)
mov    $0x22,%edi
call   1030 <putchar@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edx
mov    (%rsp),%rdi
mov    $0x100000,%esi
call   1060 <fgets@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12dc <main+0x14c>
lea    0xe93(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    125e <main+0xce>
nopl   (%rax)
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x22,%rax
ja     1280 <main+0xf0>
movslq (%r12,%rax,4),%rcx
add    %r12,%rcx
jmp    *%rcx
mov    %r14,%rdi
jmp    1253 <main+0xc3>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x5c,%al
jne    1290 <main+0x100>
mov    %r13,%rdi
jmp    1253 <main+0xc3>
nopl   0x0(%rax)
movsbl %al,%edi
call   10b0 <isascii@plt>
test   %rax,%rax
je     12c5 <main+0x135>
movsbl (%rbx),%edi
call   1090 <isprint@plt>
test   %rax,%rax
je     12c5 <main+0x135>
movsbl (%rbx),%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
jmp    125e <main+0xce>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
jmp    1253 <main+0xc3>
movsbl (%rbx),%esi
lea    0xe1d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
jmp    125e <main+0xce>
lea    0xe0e(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cd8(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd80(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [50 x i8] c"Usage: %s identifier < filename.txt > filename.h\0A\00"
@.str.1 = [25 x i8] c"static const char %s[] =\00"
@stdin = global i32 0
@.str.2 = [9 x i8] c" \\\0A \22\00"
@.str.3 = [3 x i8] c"\\\22\00"
@.str.4 = [3 x i8] c"\\\\\00"
@.str.5 = [3 x i8] c"\\r\00"
@.str.6 = [3 x i8] c"\\n\00"
@.str.7 = [5 x i8] c"\\0%o\00"
@.str.8 = [2 x i8] c"\22\00"
@.str.9 = [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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = call i8* @malloc(i32 1048576)
store i8* %22, i8** %6
br label %23
23: ; preds = %90, %17
%24 = load i8*, i8** %6
%25 = load i32, i32* @stdin
%26 = call i8* @fgets(i8* %24, i32 1048576, i32 %25)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %30
29: ; preds = %23
br label %92
30: ; preds = %23
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %87, %30
%33 = load i8*, i8** %7
%34 = load i8, i8* %33
%35 = icmp ne i8 %34, 0
br i1 %35, label %36, label %90
36: ; preds = %32
%37 = load i8*, i8** %7
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 34
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %87
43: ; preds = %36
%44 = load i8*, i8** %7
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 92
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %86
50: ; preds = %43
%51 = load i8*, i8** %7
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 13
br i1 %54, label %55, label %57
55: ; preds = %50
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %85
57: ; preds = %50
%58 = load i8*, i8** %7
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 10
br i1 %61, label %62, label %64
62: ; preds = %57
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %84
64: ; preds = %57
%65 = load i8*, i8** %7
%66 = load i8, i8* %65
%67 = call i64 @isascii(i8 signext %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %78
69: ; preds = %64
%70 = load i8*, i8** %7
%71 = load i8, i8* %70
%72 = call i64 @isprint(i8 signext %71)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %69
%75 = load i8*, i8** %7
%76 = load i8, i8* %75
%77 = call i32 @putchar(i8 signext %76)
br label %83
78: ; preds = %69, %64
%79 = load i8*, i8** %7
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %81)
br label %83
83: ; preds = %78, %74
br label %84
84: ; preds = %83, %62
br label %85
85: ; preds = %84, %55
br label %86
86: ; preds = %85, %48
br label %87
87: ; preds = %86, %41
%88 = load i8*, i8** %7
%89 = getelementptr inbounds i8, i8* %88, i32 1
store i8* %89, i8** %7
br label %32
90: ; preds = %32
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %23
92: ; preds = %29
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [50 x i8] c"Usage: %s identifier < filename.txt > filename.h\0A\00"
@.str.1 = [25 x i8] c"static const char %s[] =\00"
@stdin = global i32 0
@.str.2 = [9 x i8] c" \\\0A \22\00"
@.str.3 = [3 x i8] c"\\\22\00"
@.str.4 = [3 x i8] c"\\\\\00"
@.str.5 = [3 x i8] c"\\r\00"
@.str.6 = [3 x i8] c"\\n\00"
@.str.7 = [5 x i8] c"\\0%o\00"
@str = [2 x i8] c";\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = tail call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%14 = load i32, i32* @stdin
%15 = tail call i8* @fgets(i8* %13, i32 1048576, i32 %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %52, label %17
17: ; preds = %9, %47
%18 = phi i8* [ %50, %47 ], [ %15, %9 ]
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %45, %17
%21 = phi i8* [ %18, %17 ], [ %46, %45 ]
%22 = load i8, i8* %21
switch i8 %22, label %31 [
i8 0, label %47
i8 34, label %23
i8 92, label %25
i8 13, label %27
i8 10, label %29
]
23: ; preds = %20
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %45
25: ; preds = %20
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %45
27: ; preds = %20
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %45
29: ; preds = %20
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %45
31: ; preds = %20
%32 = tail call i64 @isascii(i8 signext %22)
%33 = icmp eq i64 %32, 0
br i1 %33, label %41, label %34
34: ; preds = %31
%35 = load i8, i8* %21
%36 = tail call i64 @isprint(i8 signext %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %34
%39 = load i8, i8* %21
%40 = tail call i32 @putchar(i8 signext %39)
br label %45
41: ; preds = %34, %31
%42 = load i8, i8* %21
%43 = sext i8 %42 to i32
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %25, %29, %41, %38, %27, %23
%46 = getelementptr inbounds i8, i8* %21, i64 1
br label %20
47: ; preds = %20
%48 = tail call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 34)
%49 = load i32, i32* @stdin
%50 = tail call i8* @fgets(i8* %13, i32 1048576, i32 %49)
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %17
52: ; preds = %47, %9
%53 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret i32 0
}