#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 EOF;
int /*<<< orphan*/ emit_name(char const *);
int getchar();
int /*<<< orphan*/ printf(char *, ...);
int emit(const char *name) {
  int col = 18;
  printf("static const char ");
  emit_name(name);
  printf("_source[] = \"%s\";\n\n", name);
  printf("static const unsigned char ");
  emit_name(name);
  printf("_bytes[] = {");
  for (;;) {
    int ch = getchar();
    if (ch == EOF) {
      printf("\n};\n");
      return 0;
    }
    if (col >= 18) {
      printf("\n  ");
      col = 0;
    }
    printf("%3d,", ch);
    col++;
  }
}


x86 assembly (clang, -O0):
<emit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x12,-0xc(%rbp)
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <emit_name@plt>
mov    -0x8(%rbp),%rsi
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <emit_name@plt>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2e43(%rip),%rcx
cmp    (%rcx),%eax
jne    11c3 <emit+0x93>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret
cmpl   $0x12,-0xc(%rbp)
jl     11e2 <emit+0xb2>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1191 <emit+0x61>

x86 assembly (clang, -O2):
<emit>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
lea    0xeae(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <emit_name@plt>
lea    0xeab(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <emit_name@plt>
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e44(%rip),%r15
cmp    (%r15),%eax
jne    11c0 <emit+0x80>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
mov    $0x12,%ebx
lea    0xe82(%rip),%r14
lea    0xe7f(%rip),%r12
jmp    11fd <emit+0xbd>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
je     11a9 <emit+0x69>
cmp    $0x12,%ebx
jl     11e0 <emit+0xa0>
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e0 <emit+0xa0>

LLVM IR (-O0):
@.str = [19 x i8] c"static const char \00"
@.str.1 = [20 x i8] c"_source[] = \22%s\22;\0A\0A\00"
@.str.2 = [28 x i8] c"static const unsigned char \00"
@.str.3 = [13 x i8] c"_bytes[] = {\00"
@EOF = global i32 0
@.str.4 = [5 x i8] c"\0A};\0A\00"
@.str.5 = [4 x i8] c"\0A \00"
@.str.6 = [5 x i8] c"%3d,\00"
define i32 @emit(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 18, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%6 = load i8*, i8** %2
%7 = call i32 @emit_name(i8* %6)
%8 = load i8*, i8** %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%11 = load i8*, i8** %2
%12 = call i32 @emit_name(i8* %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %26, %1
%15 = call i32 (...) @getchar()
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
21: ; preds = %14
%22 = load i32, i32* %3
%23 = icmp sge i32 %22, 18
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %26
26: ; preds = %24, %21
%27 = load i32, i32* %4
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %14
}

LLVM IR (-O2):
@.str = [19 x i8] c"static const char \00"
@.str.1 = [20 x i8] c"_source[] = \22%s\22;\0A\0A\00"
@.str.2 = [28 x i8] c"static const unsigned char \00"
@.str.3 = [13 x i8] c"_bytes[] = {\00"
@EOF = global i32 0
@.str.5 = [4 x i8] c"\0A \00"
@.str.6 = [5 x i8] c"%3d,\00"
@str = [4 x i8] c"\0A};\00"
define i32 @emit(i8* %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @emit_name(i8* %0)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @emit_name(i8* %0)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 (...) @getchar()
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %24, label %11
11: ; preds = %1, %17
%12 = phi i32 [ %21, %17 ], [ %8, %1 ]
%13 = phi i32 [ %20, %17 ], [ 18, %1 ]
%14 = icmp sgt i32 %13, 17
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %17
17: ; preds = %11, %15
%18 = phi i32 [ 0, %15 ], [ %13, %11 ]
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %12)
%20 = add nsw i32 %18, 1
%21 = tail call i32 (...) @getchar()
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %11
24: ; preds = %17, %1
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
ret i32 0
}