#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 */
int /*<<< orphan*/ exit(int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ interface(char *, char *, char *);
scalar_t__ isspace(char);
int /*<<< orphan*/ mangle(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sscanf(char *, char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *filename = 0;
  char *body = 0;
  FILE *file = 0;
  char line[4096];
  char rtype[4096];
  char ident[4096];
  char args[4096];
  char mangled[4096];
  if (argc <= 1) {
    fprintf(stderr, "Usage %s filename {optional body}\n", argv[0]);
    exit(1);
  }
  filename = argv[1];
  if (argc > 2) {
    body = argv[2];
  }
  file = fopen(filename, "r");
  if (!file) {
    perror(argv[0]);
    return 1;
  }
  while (fgets(line, 4096, file) && line[0]) {
    if (isspace(line[0]))
      continue;
    rtype[0] = 0;
    ident[0] = 0;
    sscanf(line, "%[a-zA-Z0-9_] %[a-zA-Z0-9_] ( %[^)] )", rtype, ident, args);
    if (rtype[0] && ident[0]) {
      puts("#include \"mpi.h\"");
      puts("#include \"mpi_config.h\"");
      puts("#include \"mpi_implementation.h\"");
      if (body) {
        mangle(ident, mangled);
        printf("void %s%s\n", mangled, body);
      } else {
        interface(rtype, ident, args);
      }
      return 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     1211 <main+0x61>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdfe(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1233 <main+0x83>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    126a <main+0xba>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c0 <main+0x210>
jmp    126f <main+0xbf>
lea    -0x1030(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x1000,%esi
call   1070 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x5031(%rbp)
je     12ac <main+0xfc>
movsbl -0x1030(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x5031(%rbp)
mov    -0x5031(%rbp),%al
test   $0x1,%al
jne    12bf <main+0x10f>
jmp    13b9 <main+0x209>
movsbl -0x1030(%rbp),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
je     12da <main+0x12a>
jmp    126f <main+0xbf>
movb   $0x0,-0x2030(%rbp)
movb   $0x0,-0x3030(%rbp)
lea    -0x1030(%rbp),%rdi
lea    -0x2030(%rbp),%rdx
lea    -0x3030(%rbp),%rcx
lea    -0x4030(%rbp),%r8
lea    0xd1a(%rip),%rsi
call   1090 <sscanf@plt>
movsbl -0x2030(%rbp),%eax
cmp    $0x0,%eax
je     13b4 <main+0x204>
movsbl -0x3030(%rbp),%eax
cmp    $0x0,%eax
je     13b4 <main+0x204>
lea    0xd14(%rip),%rdi
call   1030 <puts@plt>
lea    0xd19(%rip),%rdi
call   1030 <puts@plt>
lea    0xd25(%rip),%rdi
call   1030 <puts@plt>
cmpq   $0x0,-0x20(%rbp)
je     138e <main+0x1de>
lea    -0x3030(%rbp),%rdi
lea    -0x5030(%rbp),%rsi
call   10d0 <mangle@plt>
lea    -0x5030(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xd10(%rip),%rdi
call   1040 <printf@plt>
jmp    13a8 <main+0x1f8>
lea    -0x2030(%rbp),%rdi
lea    -0x3030(%rbp),%rsi
lea    -0x4030(%rbp),%rdx
call   1050 <interface@plt>
movl   $0x0,-0x4(%rbp)
jmp    13c0 <main+0x210>
jmp    126f <main+0xbf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x5040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x5018,%rsp
mov    %rsi,%rbp
cmp    $0x1,%edi
jle    1361 <main+0x1b1>
mov    %edi,%eax
mov    0x8(%rbp),%rdi
cmp    $0x2,%eax
jne    11dd <main+0x2d>
xor    %r14d,%r14d
jmp    11e1 <main+0x31>
mov    0x10(%rbp),%r14
lea    0xe3b(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1321 <main+0x171>
mov    %rax,%rbx
lea    0x2010(%rsp),%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
xor    %ecx,%ecx
test   %rax,%rax
je     134d <main+0x19d>
mov    0x2010(%rsp),%al
test   %al,%al
je     134d <main+0x19d>
mov    %r14,0x8(%rsp)
lea    0xdf1(%rip),%r12
lea    0x2010(%rsp),%rbp
lea    0x1010(%rsp),%r13
lea    0x10(%rsp),%r14
lea    0x3010(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1060 <isspace@plt>
test   %rax,%rax
jne    12a0 <main+0xf0>
movb   $0x0,0x1010(%rsp)
movb   $0x0,0x10(%rsp)
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1090 <sscanf@plt>
cmpb   $0x0,0x1010(%rsp)
je     12a0 <main+0xf0>
cmpb   $0x0,0x10(%rsp)
jne    12ca <main+0x11a>
nop
mov    %rbp,%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     134b <main+0x19b>
movzbl 0x2010(%rsp),%eax
test   %al,%al
jne    1260 <main+0xb0>
jmp    134b <main+0x19b>
lea    0xd7a(%rip),%rdi
call   1030 <puts@plt>
lea    0xd7f(%rip),%rdi
call   1030 <puts@plt>
lea    0xd8b(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rbp
test   %rbp,%rbp
je     1331 <main+0x181>
lea    0x10(%rsp),%rdi
lea    0x4010(%rsp),%rbx
mov    %rbx,%rsi
call   10d0 <mangle@plt>
lea    0xd80(%rip),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1040 <printf@plt>
jmp    134b <main+0x19b>
mov    0x0(%rbp),%rdi
call   10b0 <perror@plt>
mov    $0x1,%ecx
jmp    134d <main+0x19d>
lea    0x1010(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x3010(%rsp),%rdx
call   1050 <interface@plt>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x5018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xc8b(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"Usage %s filename {optional body}\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [38 x i8] c"%[a-zA-Z0-9_] %[a-zA-Z0-9_] ( %[^)] )\00"
@.str.3 = [17 x i8] c"#include \22mpi.h\22\00"
@.str.4 = [24 x i8] c"#include \22mpi_config.h\22\00"
@.str.5 = [32 x i8] c"#include \22mpi_implementation.h\22\00"
@.str.6 = [11 x i8] c"void %s%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca [4096 x i8]
%10 = alloca [4096 x i8]
%11 = alloca [4096 x i8]
%12 = alloca [4096 x i8]
%13 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i8* null, i8** %7
store i32* null, i32** %8
%14 = load i32, i32* %4
%15 = icmp sle i32 %14, 1
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %6
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, 2
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
store i8* %32, i8** %7
br label %33
33: ; preds = %29, %23
%34 = load i8*, i8** %6
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %35, i32** %8
%36 = load i32*, i32** %8
%37 = icmp ne i32* %36, null
br i1 %37, label %43, label %38
38: ; preds = %33
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 0
%41 = load i8*, i8** %40
%42 = call i32 @perror(i8* %41)
store i32 1, i32* %3
br label %100
43: ; preds = %33
br label %44
44: ; preds = %98, %61, %43
%45 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%46 = load i32*, i32** %8
%47 = call i64 @fgets(i8* %45, i32 4096, i32* %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %44
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 0
br label %54
54: ; preds = %49, %44
%55 = phi i1 [ false, %44 ], [ %53, %49 ]
br i1 %55, label %56, label %99
56: ; preds = %54
%57 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%58 = load i8, i8* %57
%59 = call i64 @isspace(i8 signext %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %56
br label %44
62: ; preds = %56
%63 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
store i8 0, i8* %63
%64 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
store i8 0, i8* %64
%65 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%66 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%67 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%68 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%69 = call i32 @sscanf(i8* %65, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %66, i8* %67, i8* %68)
%70 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %98
74: ; preds = %62
%75 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %98
79: ; preds = %74
%80 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%81 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%82 = call i32 @puts(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%83 = load i8*, i8** %7
%84 = icmp ne i8* %83, null
br i1 %84, label %85, label %92
85: ; preds = %79
%86 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%87 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%88 = call i32 @mangle(i8* %86, i8* %87)
%89 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%90 = load i8*, i8** %7
%91 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %89, i8* %90)
br label %97
92: ; preds = %79
%93 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%94 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%95 = getelementptr inbounds [4096 x i8], [4096 x i8]* %12, i64 0, i64 0
%96 = call i32 @interface(i8* %93, i8* %94, i8* %95)
br label %97
97: ; preds = %92, %85
store i32 0, i32* %3
br label %100
98: ; preds = %74, %62
br label %44
99: ; preds = %54
store i32 0, i32* %3
br label %100
100: ; preds = %99, %97, %38
%101 = load i32, i32* %3
ret i32 %101
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"Usage %s filename {optional body}\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [38 x i8] c"%[a-zA-Z0-9_] %[a-zA-Z0-9_] ( %[^)] )\00"
@.str.3 = [17 x i8] c"#include \22mpi.h\22\00"
@.str.4 = [24 x i8] c"#include \22mpi_config.h\22\00"
@.str.5 = [32 x i8] c"#include \22mpi_implementation.h\22\00"
@.str.6 = [11 x i8] c"void %s%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = alloca [4096 x i8]
%5 = alloca [4096 x i8]
%6 = alloca [4096 x i8]
%7 = alloca [4096 x i8]
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%13 = icmp slt i32 %0, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = icmp eq i32 %0, 2
br i1 %22, label %26, label %23
23: ; preds = %19
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
br label %26
26: ; preds = %23, %19
%27 = phi i8* [ %25, %23 ], [ null, %19 ]
%28 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i32* %28, null
br i1 %29, label %36, label %30
30: ; preds = %26
%31 = call i64 @fgets(i8* %8, i32 4096, i32* %28)
%32 = icmp ne i64 %31, 0
%33 = load i8, i8* %8
%34 = icmp ne i8 %33, 0
%35 = select i1 %32, i1 %34, i1 false
br i1 %35, label %39, label %66
36: ; preds = %26
%37 = load i8*, i8** %1
%38 = tail call i32 @perror(i8* %37)
br label %66
39: ; preds = %30, %43
%40 = phi i8 [ %46, %43 ], [ %33, %30 ]
%41 = call i64 @isspace(i8 signext %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %49, label %43
43: ; preds = %39, %49
%44 = call i64 @fgets(i8* %8, i32 4096, i32* %28)
%45 = icmp ne i64 %44, 0
%46 = load i8, i8* %8
%47 = icmp ne i8 %46, 0
%48 = select i1 %45, i1 %47, i1 false
br i1 %48, label %39, label %66
49: ; preds = %39
store i8 0, i8* %9
store i8 0, i8* %10
%50 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %9, i8* %10, i8* %11)
%51 = load i8, i8* %9
%52 = icmp ne i8 %51, 0
%53 = load i8, i8* %10
%54 = icmp ne i8 %53, 0
%55 = select i1 %52, i1 %54, i1 false
br i1 %55, label %56, label %43
56: ; preds = %49
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%60 = icmp eq i8* %27, null
br i1 %60, label %64, label %61
61: ; preds = %56
%62 = call i32 @mangle(i8* %10, i8* %12)
%63 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %12, i8* %27)
br label %66
64: ; preds = %56
%65 = call i32 @interface(i8* %9, i8* %10, i8* %11)
br label %66
66: ; preds = %43, %30, %61, %64, %36
%67 = phi i32 [ 1, %36 ], [ 0, %64 ], [ 0, %61 ], [ 0, %30 ], [ 0, %43 ]
ret i32 %67
}