#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*/ clean_token_order();
int /*<<< orphan*/ create_header_source();
int create_proc_source();
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ get_token_order_top();
char *malloc(int);
int /*<<< orphan*/ parser_c_source();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read_file(char *);
int /*<<< orphan*/ set_token_order_current(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ system(char *);
int split_c_source(char *filename) {
  int function_count;
  int i;
  char *llvm_command;
  printf("[C Source Parser Start]\n");
  read_file(filename);
  set_token_order_current(get_token_order_top());
  parser_c_source();
  function_count = create_proc_source();
  create_header_source();
  clean_token_order();
  printf(" -> Function Count: %d\n", function_count);
  printf("[LLVM Compile Start]\n");
  llvm_command = malloc(256);
  for (i = 0; i < function_count; i++) {
    sprintf(llvm_command, "clang -S -m32 -O3 -emit-llvm __%03d.c", i);
    system(llvm_command);
  }
  free(llvm_command);
  return function_count;
}


x86 assembly (clang, -O0):
<split_c_source>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1070 <read_file@plt>
mov    $0x0,%al
call   1080 <get_token_order_top@plt>
mov    %eax,%edi
call   10b0 <set_token_order_current@plt>
mov    $0x0,%al
call   1040 <parser_c_source@plt>
mov    $0x0,%al
call   10d0 <create_proc_source@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   10c0 <create_header_source@plt>
mov    $0x0,%al
call   10a0 <clean_token_order@plt>
mov    -0xc(%rbp),%esi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x100,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    127a <split_c_source+0xba>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xde9(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <system@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1244 <split_c_source+0x84>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_c_source>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe5d(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1080 <read_file@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1090 <get_token_order_top@plt>
mov    %eax,%edi
call   10c0 <set_token_order_current@plt>
xor    %eax,%eax
call   1040 <parser_c_source@plt>
xor    %eax,%eax
call   10e0 <create_proc_source@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   10d0 <create_header_source@plt>
xor    %eax,%eax
call   10b0 <clean_token_order@plt>
lea    0xddc(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe21(%rip),%rdi
call   1050 <puts@plt>
mov    $0x100,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbp
test   %r14d,%r14d
jle    127d <split_c_source+0xad>
lea    0xdc5(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   10f0 <sprintf@plt>
mov    %rbp,%rdi
call   1060 <system@plt>
add    $0x1,%ebx
cmp    %ebx,%r14d
jne    1260 <split_c_source+0x90>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"[C Source Parser Start]\0A\00"
@.str.1 = [24 x i8] c" -> Function Count: %d\0A\00"
@.str.2 = [22 x i8] c"[LLVM Compile Start]\0A\00"
@.str.3 = [38 x i8] c"clang -S -m32 -O3 -emit-llvm __%03d.c\00"
define i32 @split_c_source(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%7 = load i8*, i8** %2
%8 = call i32 @read_file(i8* %7)
%9 = call i32 (...) @get_token_order_top()
%10 = call i32 @set_token_order_current(i32 %9)
%11 = call i32 (...) @parser_c_source()
%12 = call i32 (...) @create_proc_source()
store i32 %12, i32* %3
%13 = call i32 (...) @create_header_source()
%14 = call i32 (...) @clean_token_order()
%15 = load i32, i32* %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%18 = call i8* @malloc(i32 256)
store i8* %18, i8** %5
store i32 0, i32* %4
br label %19
19: ; preds = %29, %1
%20 = load i32, i32* %4
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %32
23: ; preds = %19
%24 = load i8*, i8** %5
%25 = load i32, i32* %4
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = load i8*, i8** %5
%28 = call i32 @system(i8* %27)
br label %29
29: ; preds = %23
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %19
32: ; preds = %19
%33 = load i8*, i8** %5
%34 = call i32 @free(i8* %33)
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str.1 = [24 x i8] c" -> Function Count: %d\0A\00"
@.str.3 = [38 x i8] c"clang -S -m32 -O3 -emit-llvm __%03d.c\00"
@str = [24 x i8] c"[C Source Parser Start]\00"
@str.4 = [21 x i8] c"[LLVM Compile Start]\00"
define i32 @split_c_source(i8* %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @read_file(i8* %0)
%4 = tail call i32 (...) @get_token_order_top()
%5 = tail call i32 @set_token_order_current(i32 %4)
%6 = tail call i32 (...) @parser_c_source()
%7 = tail call i32 (...) @create_proc_source()
%8 = tail call i32 (...) @create_header_source()
%9 = tail call i32 (...) @clean_token_order()
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.4, i64 0, i64 0))
%12 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%13 = icmp sgt i32 %7, 0
br i1 %13, label %14, label %20
14: ; preds = %1, %14
%15 = phi i32 [ %18, %14 ], [ 0, %1 ]
%16 = tail call i32 @sprintf(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = tail call i32 @system(i8* %12)
%18 = add nuw nsw i32 %15, 1
%19 = icmp eq i32 %18, %7
br i1 %19, label %20, label %14
20: ; preds = %14, %1
%21 = tail call i32 @free(i8* %12)
ret i32 %7
}