#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*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
unsigned char *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/,
                    int /*<<< orphan*/, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int slabextract(unsigned char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int infd;
  unsigned char *InputBuffer;
  int InputBufferSize;
  if (argc != 2) {
    printf("usage: %s <input file>\n", argv[0]);
    return 1;
  }
  infd = open(argv[1], O_RDONLY);
  if (infd < 0) {
    fprintf(stderr, "Error: Failed to open %s: %s\n", argv[1], strerror(errno));
    return 1;
  }
  InputBufferSize = lseek(infd, 0, SEEK_END);
  if (InputBufferSize < 0) {
    fprintf(stderr, "Error: Failed to lseek \"%s\": %s\n", argv[1],
            strerror(errno));
    return 1;
  }
  InputBuffer = mmap(NULL, InputBufferSize, PROT_READ, MAP_PRIVATE, infd, 0);
  if (InputBuffer < 0) {
    fprintf(stderr, "Error: Failed to mmap %s: %s\n", argv[1], strerror(errno));
    return 1;
  }
  if (InputBufferSize < 4) {
    fprintf(stderr, "Error: \"%s\" is too small to be a SLAB file.\n", argv[1]);
    return 1;
  }
  return slabextract(InputBuffer, InputBufferSize);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11af <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1348 <main+0x1d8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    121c <main+0xac>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xe0f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1348 <main+0x1d8>
mov    -0x14(%rbp),%edi
mov    0x2dba(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1286 <main+0x116>
mov    0x2d85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xdc3(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1348 <main+0x1d8>
mov    -0x24(%rbp),%esi
mov    0x2d68(%rip),%rax
mov    (%rax),%edx
mov    0x2d1f(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jae    1304 <main+0x194>
mov    0x2d07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2ce7(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
lea    0xd66(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1348 <main+0x1d8>
cmpl   $0x4,-0x24(%rbp)
jge    1339 <main+0x1c9>
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd4f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1348 <main+0x1d8>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <slabextract@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11fa <main+0x8a>
mov    0x8(%rbx),%rdi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     120b <main+0x9b>
mov    %eax,%ebp
mov    0x2e45(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
test   %eax,%eax
js     122f <main+0xbf>
mov    %eax,%r14d
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
mov    0x2df7(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14d,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
cmp    $0x3,%r14d
ja     126a <main+0xfa>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe66(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1260 <main+0xf0>
mov    (%rbx),%rsi
lea    0xdfc(%rip),%rdi
call   1050 <printf@plt>
jmp    1260 <main+0xf0>
mov    0x2db6(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdeb(%rip),%rsi
jmp    1251 <main+0xe1>
mov    0x2d92(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xde5(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rax,%rdi
mov    %r14d,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <slabextract@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"usage: %s <input file>\0A\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"Error: Failed to open %s: %s\0A\00"
@errno = global i32 0
@SEEK_END = global i32 0
@.str.2 = [33 x i8] c"Error: Failed to lseek \22%s\22: %s\0A\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@.str.3 = [30 x i8] c"Error: Failed to mmap %s: %s\0A\00"
@.str.4 = [45 x i8] c"Error: \22%s\22 is too small to be a SLAB file.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 1, i32* %3
br label %75
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %16
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %30)
store i32 1, i32* %3
br label %75
32: ; preds = %16
%33 = load i32, i32* %6
%34 = load i32, i32* @SEEK_END
%35 = call i32 @lseek(i32 %33, i32 0, i32 %34)
store i32 %35, i32* %8
%36 = load i32, i32* %8
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %46
38: ; preds = %32
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %42, i8* %44)
store i32 1, i32* %3
br label %75
46: ; preds = %32
%47 = load i32, i32* %8
%48 = load i32, i32* @PROT_READ
%49 = load i32, i32* @MAP_PRIVATE
%50 = load i32, i32* %6
%51 = call i8* @mmap(i32* null, i32 %47, i32 %48, i32 %49, i32 %50, i32 0)
store i8* %51, i8** %7
%52 = load i8*, i8** %7
%53 = icmp ult i8* %52, null
br i1 %53, label %54, label %62
54: ; preds = %46
%55 = load i32, i32* @stderr
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
%59 = load i32, i32* @errno
%60 = call i8* @strerror(i32 %59)
%61 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %58, i8* %60)
store i32 1, i32* %3
br label %75
62: ; preds = %46
%63 = load i32, i32* %8
%64 = icmp slt i32 %63, 4
br i1 %64, label %65, label %71
65: ; preds = %62
%66 = load i32, i32* @stderr
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 1
%69 = load i8*, i8** %68
%70 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %69)
store i32 1, i32* %3
br label %75
71: ; preds = %62
%72 = load i8*, i8** %7
%73 = load i32, i32* %8
%74 = call i32 @slabextract(i8* %72, i32 %73)
store i32 %74, i32* %3
br label %75
75: ; preds = %71, %65, %54, %38, %24, %11
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
@.str = [24 x i8] c"usage: %s <input file>\0A\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"Error: Failed to open %s: %s\0A\00"
@errno = global i32 0
@SEEK_END = global i32 0
@.str.2 = [33 x i8] c"Error: Failed to lseek \22%s\22: %s\0A\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@.str.4 = [45 x i8] c"Error: \22%s\22 is too small to be a SLAB file.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %40
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %7
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %8
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %17)
br label %40
19: ; preds = %7
%20 = load i32, i32* @SEEK_END
%21 = tail call i32 @lseek(i32 %11, i32 0, i32 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %8
%26 = load i32, i32* @errno
%27 = tail call i8* @strerror(i32 %26)
%28 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %25, i8* %27)
br label %40
29: ; preds = %19
%30 = load i32, i32* @PROT_READ
%31 = load i32, i32* @MAP_PRIVATE
%32 = tail call i8* @mmap(i32* null, i32 %21, i32 %30, i32 %31, i32 %11, i32 0)
%33 = icmp ult i32 %21, 4
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %8
%37 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %36)
br label %40
38: ; preds = %29
%39 = tail call i32 @slabextract(i8* %32, i32 %21)
br label %40
40: ; preds = %38, %34, %23, %13, %4
%41 = phi i32 [ 1, %4 ], [ 1, %13 ], [ 1, %23 ], [ 1, %34 ], [ %39, %38 ]
ret i32 %41
}