#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 */
struct Symbol {
  int dummy;
};
struct String {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
struct String *compile(struct Symbol *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct Symbol *parse(char *);
int /*<<< orphan*/ printSymbol(int /*<<< orphan*/, struct Symbol *,
                               int /*<<< orphan*/);
char *read(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
size_t write(int /*<<< orphan*/ *, struct String *);
int main(int argc, char **argv) {
  FILE *input = stdin;
  FILE *output = stdout;
  char *data = read(input);
  if (data == NULL) {
    return 1;
  }
  fprintf(stderr, "%s\n", data);
  struct Symbol *symbols = parse(data);
  printSymbol(stderr, symbols, 0);
  struct String *assembly = compile(symbols);
  size_t numBytes = write(output, assembly);
  if (numBytes != 0) {
    fprintf(stderr, "%i bytes written\n", numBytes);
    return 0;
  } else {
    fprintf(stderr, "Error: no bytes written\n");
    return 1;
  }
}


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    0x2e6b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <read@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b6 <main+0x56>
movl   $0x1,-0x4(%rbp)
jmp    1260 <main+0x100>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1080 <parse@plt>
mov    %rax,-0x30(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1070 <printSymbol@plt>
mov    -0x30(%rbp),%rdi
call   1040 <compile@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <write@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1242 <main+0xe2>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rdx
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1260 <main+0x100>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e7a(%rip),%rax
mov    (%rax),%rdi
mov    0x2e58(%rip),%rax
mov    (%rax),%r14
call   1050 <read@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1203 <main+0xa3>
mov    %rax,%rbx
mov    0x2e44(%rip),%r15
mov    (%r15),%edi
lea    0xe62(%rip),%rsi
xor    %ebp,%ebp
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <parse@plt>
mov    %rax,%rbx
mov    (%r15),%edi
mov    %rax,%rsi
xor    %edx,%edx
call   1070 <printSymbol@plt>
mov    %rbx,%rdi
call   1040 <compile@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <write@plt>
mov    (%r15),%edi
test   %rax,%rax
je     11f0 <main+0x90>
lea    0xe20(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1203 <main+0xa3>
lea    0xe1f(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.Symbol = type { i32 }
%struct.String = type { i32 }
@stdin = global i32* null
@stdout = global i32* null
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [18 x i8] c"%i bytes written\0A\00"
@.str.2 = [25 x i8] c"Error: no bytes written\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca %struct.Symbol*
%10 = alloca %struct.String*
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32*, i32** @stdin
store i32* %12, i32** %6
%13 = load i32*, i32** @stdout
store i32* %13, i32** %7
%14 = load i32*, i32** %6
%15 = call i8* @read(i32* %14)
store i8* %15, i8** %8
%16 = load i8*, i8** %8
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 1, i32* %3
br label %42
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %8
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %8
%24 = call %struct.Symbol* @parse(i8* %23)
store %struct.Symbol* %24, %struct.Symbol** %9
%25 = load i32, i32* @stderr
%26 = load %struct.Symbol*, %struct.Symbol** %9
%27 = call i32 @printSymbol(i32 %25, %struct.Symbol* %26, i32 0)
%28 = load %struct.Symbol*, %struct.Symbol** %9
%29 = call %struct.String* @compile(%struct.Symbol* %28)
store %struct.String* %29, %struct.String** %10
%30 = load i32*, i32** %7
%31 = load %struct.String*, %struct.String** %10
%32 = call i64 @write(i32* %30, %struct.String* %31)
store i64 %32, i64* %11
%33 = load i64, i64* %11
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %19
%36 = load i32, i32* @stderr
%37 = load i64, i64* %11
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i64 %37)
store i32 0, i32* %3
br label %42
39: ; preds = %19
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %42
42: ; preds = %39, %35, %18
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
%struct.Symbol = type { i32 }
%struct.String = type { i32 }
@stdin = global i32* null
@stdout = global i32* null
@stderr = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [18 x i8] c"%i bytes written\0A\00"
@.str.2 = [25 x i8] c"Error: no bytes written\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32*, i32** @stdin
%4 = load i32*, i32** @stdout
%5 = tail call i8* @read(i32* %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %21, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
%10 = tail call %struct.Symbol* @parse(i8* %5)
%11 = load i32, i32* @stderr
%12 = tail call i32 @printSymbol(i32 %11, %struct.Symbol* %10, i32 0)
%13 = tail call %struct.String* @compile(%struct.Symbol* %10)
%14 = tail call i64 @write(i32* %4, %struct.String* %13)
%15 = icmp eq i64 %14, 0
%16 = load i32, i32* @stderr
br i1 %15, label %19, label %17
17: ; preds = %7
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i64 %14)
br label %21
19: ; preds = %7
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %17, %19, %2
%22 = phi i32 [ 1, %2 ], [ 0, %17 ], [ 1, %19 ]
ret i32 %22
}