#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_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ try_embedded_fsb(int /*<<< orphan*/ *);
int /*<<< orphan*/ try_multistream_fsb(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  FILE *infile;
  int rc;
  if (argc != 2) {
    printf("fsbii 0.8 - convert multi-stream fsb into single-stream fsbs, or "
           "extract embedded fsbs\n"
           "usage: fsbii blah.fsb\n");
    exit(EXIT_FAILURE);
  }
  infile = fopen(argv[1], "rb");
  do {
    if (infile == NULL) {
      perror("error "
             "opening input");
      exit(EXIT_FAILURE);
    }
  } while (0);
  if (!try_multistream_fsb(infile) && !try_embedded_fsb(infile)) {
    printf("Sorry, couldn't make any sense of this file.\n");
    exit(EXIT_FAILURE);
  }
  rc = fclose(infile);
  do {
    if (rc != 0) {
      perror("error "
             "closing input file");
      exit(EXIT_FAILURE);
    }
  } while (0);
  printf("Success!\n");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11aa <main+0x3a>
lea    0xe69(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xeb5(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e7 <main+0x77>
lea    0xe9d(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11ec <main+0x7c>
mov    -0x18(%rbp),%rdi
call   1060 <try_multistream_fsb@plt>
cmp    $0x0,%eax
jne    122a <main+0xba>
mov    -0x18(%rbp),%rdi
call   1030 <try_embedded_fsb@plt>
cmp    $0x0,%eax
jne    122a <main+0xba>
lea    0xe6e(%rip),%rdi
call   1050 <printf@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     125a <main+0xea>
lea    0xe6c(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    125f <main+0xef>
lea    0xe66(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    1199 <main+0x29>
mov    0x8(%rsi),%rdi
lea    0xe7f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    11b3 <main+0x43>
lea    0xe71(%rip),%rdi
call   1080 <perror@plt>
jmp    11a5 <main+0x35>
lea    0xec6(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <try_multistream_fsb@plt>
test   %eax,%eax
jne    11d7 <main+0x67>
mov    %rbx,%rdi
call   1040 <try_embedded_fsb@plt>
test   %eax,%eax
jne    11d7 <main+0x67>
lea    0xe5b(%rip),%rdi
jmp    11a0 <main+0x30>
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %eax,%eax
jne    11fd <main+0x8d>
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe13(%rip),%rdi
call   1080 <perror@plt>
jmp    11a5 <main+0x35>

LLVM IR (-O0):
@.str = [110 x i8] c"fsbii 0.8 - convert multi-stream fsb into single-stream fsbs, or extract embedded fsbs\0Ausage: fsbii blah.fsb\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [20 x i8] c"error opening input\00"
@.str.3 = [46 x i8] c"Sorry, couldn't make any sense of this file.\0A\00"
@.str.4 = [25 x i8] c"error closing input file\00"
@.str.5 = [10 x i8] c"Success!\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([110 x i8], [110 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
br label %19
19: ; preds = %14
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %19
br label %27
27: ; preds = %26
%28 = load i32*, i32** %6
%29 = call i32 @try_multistream_fsb(i32* %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %39, label %31
31: ; preds = %27
%32 = load i32*, i32** %6
%33 = call i32 @try_embedded_fsb(i32* %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %31
%36 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %31, %27
%40 = load i32*, i32** %6
%41 = call i32 @fclose(i32* %40)
store i32 %41, i32* %7
br label %42
42: ; preds = %39
%43 = load i32, i32* %7
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %42
br label %50
50: ; preds = %49
%51 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%52 = load i32, i32* @EXIT_SUCCESS
%53 = call i32 @exit(i32 %52)
unreachable
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [20 x i8] c"error opening input\00"
@.str.4 = [25 x i8] c"error closing input file\00"
@EXIT_SUCCESS = global i32 0
@str = [45 x i8] c"Sorry, couldn't make any sense of this file.\00"
@str.6 = [9 x i8] c"Success!\00"
@str.7 = [109 x i8] c"fsbii 0.8 - convert multi-stream fsb into single-stream fsbs, or extract embedded fsbs\0Ausage: fsbii blah.fsb\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([109 x i8], [109 x i8]* @str.7, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %8
%18 = tail call i32 @try_multistream_fsb(i32* %11)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = tail call i32 @try_embedded_fsb(i32* %11)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @exit(i32 %25)
unreachable
27: ; preds = %20, %17
%28 = tail call i32 @fclose(i32* %11)
%29 = icmp eq i32 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %27
%31 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = tail call i32 @exit(i32 %32)
unreachable
34: ; preds = %27
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.6, i64 0, i64 0))
%36 = load i32, i32* @EXIT_SUCCESS
%37 = tail call i32 @exit(i32 %36)
unreachable
}