#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 sabir {
  int dummy;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char const *);
int /*<<< orphan*/ sb_dealloc(struct sabir *);
int /*<<< orphan*/ sb_feed(struct sabir *, char *, size_t);
char *sb_finish(struct sabir *);
int /*<<< orphan*/ sb_init(struct sabir *);
int sb_load(struct sabir **, char *);
char *sb_strerror(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  struct sabir *sb;
  int ret = sb_load(&sb, "model.sb");
  if (ret) {
    fprintf(stderr, "%s: cannot load model: %s", *argv, sb_strerror(ret));
    return EXIT_FAILURE;
  }
  sb_init(sb);
  char buf[4096];
  size_t len;
  while ((len = fread(buf, 1, sizeof buf, stdin)))
    sb_feed(sb, buf, len);
  const char *lang = sb_finish(sb);
  puts(lang);
  sb_dealloc(sb);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1060 <sb_load@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1218 <main+0x88>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x103c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x1038(%rbp)
mov    -0x1c(%rbp),%edi
call   1090 <sb_strerror@plt>
mov    -0x103c(%rbp),%edi
mov    -0x1038(%rbp),%rdx
mov    %rax,%rcx
lea    0xe07(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    129e <main+0x10e>
mov    -0x18(%rbp),%rdi
call   10a0 <sb_init@plt>
lea    -0x1020(%rbp),%rdi
mov    0x2db9(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1040 <fread@plt>
mov    %rax,-0x1028(%rbp)
cmp    $0x0,%rax
je     126d <main+0xdd>
mov    -0x18(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    -0x1028(%rbp),%rdx
call   10b0 <sb_feed@plt>
jmp    1221 <main+0x91>
mov    -0x18(%rbp),%rdi
call   1080 <sb_finish@plt>
mov    %rax,-0x1030(%rbp)
mov    -0x1030(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1050 <sb_dealloc@plt>
mov    0x2d2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,%rbx
lea    0xe5d(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1060 <sb_load@plt>
test   %eax,%eax
je     11e4 <main+0x54>
mov    0x2e20(%rip),%rcx
mov    (%rcx),%ebp
mov    (%rbx),%rbx
mov    %eax,%edi
call   1090 <sb_strerror@plt>
lea    0xe3e(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    0x2df1(%rip),%rax
jmp    126d <main+0xdd>
mov    0x8(%rsp),%rdi
call   10a0 <sb_init@plt>
mov    0x2df3(%rip),%rbp
mov    0x0(%rbp),%ecx
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
call   1040 <fread@plt>
test   %rax,%rax
je     124a <main+0xba>
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   10b0 <sb_feed@plt>
mov    0x0(%rbp),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
call   1040 <fread@plt>
test   %rax,%rax
jne    1220 <main+0x90>
mov    0x8(%rsp),%rdi
call   1080 <sb_finish@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rdi
call   1050 <sb_dealloc@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
add    $0x1018,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sabir = type { i32 }
@.str = [9 x i8] c"model.sb\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"%s: cannot load model: %s\00"
@EXIT_FAILURE = global i32 0
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sabir*
%7 = alloca i32
%8 = alloca [4096 x i8]
%9 = alloca i64
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 @sb_load(%struct.sabir** %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = load i8*, i8** %16
%18 = load i32, i32* %7
%19 = call i8* @sb_strerror(i32 %18)
%20 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
store i32 %21, i32* %3
br label %43
22: ; preds = %2
%23 = load %struct.sabir*, %struct.sabir** %6
%24 = call i32 @sb_init(%struct.sabir* %23)
br label %25
25: ; preds = %30, %22
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%27 = load i32, i32* @stdin
%28 = call i64 @fread(i8* %26, i32 1, i32 4096, i32 %27)
store i64 %28, i64* %9
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load %struct.sabir*, %struct.sabir** %6
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%33 = load i64, i64* %9
%34 = call i32 @sb_feed(%struct.sabir* %31, i8* %32, i64 %33)
br label %25
35: ; preds = %25
%36 = load %struct.sabir*, %struct.sabir** %6
%37 = call i8* @sb_finish(%struct.sabir* %36)
store i8* %37, i8** %10
%38 = load i8*, i8** %10
%39 = call i32 @puts(i8* %38)
%40 = load %struct.sabir*, %struct.sabir** %6
%41 = call i32 @sb_dealloc(%struct.sabir* %40)
%42 = load i32, i32* @EXIT_SUCCESS
store i32 %42, i32* %3
br label %43
43: ; preds = %35, %14
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
%struct.sabir = type { i32 }
@.str = [9 x i8] c"model.sb\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"%s: cannot load model: %s\00"
@EXIT_FAILURE = global i32 0
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sabir*
%4 = alloca [4096 x i8]
%5 = bitcast %struct.sabir** %3 to i8*
%6 = call i32 @sb_load(%struct.sabir** %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = call i8* @sb_strerror(i32 %6)
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %10, i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
br label %35
14: ; preds = %2
%15 = load %struct.sabir*, %struct.sabir** %3
%16 = call i32 @sb_init(%struct.sabir* %15)
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%18 = load i32, i32* @stdin
%19 = call i64 @fread(i8* %17, i32 1, i32 4096, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %14, %21
%22 = phi i64 [ %26, %21 ], [ %19, %14 ]
%23 = load %struct.sabir*, %struct.sabir** %3
%24 = call i32 @sb_feed(%struct.sabir* %23, i8* %17, i64 %22)
%25 = load i32, i32* @stdin
%26 = call i64 @fread(i8* %17, i32 1, i32 4096, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %21
28: ; preds = %21, %14
%29 = load %struct.sabir*, %struct.sabir** %3
%30 = call i8* @sb_finish(%struct.sabir* %29)
%31 = call i32 @puts(i8* dereferenceable(1) %30)
%32 = load %struct.sabir*, %struct.sabir** %3
%33 = call i32 @sb_dealloc(%struct.sabir* %32)
%34 = load i32, i32* @EXIT_SUCCESS
br label %35
35: ; preds = %28, %8
%36 = phi i32 [ %13, %8 ], [ %34, %28 ]
ret i32 %36
}