#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 EXIT_FAILURE;
int EXIT_SUCCESS;
char *MAP_FAILED;
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char *addr, *stat;
  int fd, slot;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s <queue.dat> <slot 0-9>\n", argv[0]);
    return EXIT_FAILURE;
  }
  slot = atoi(argv[2]);
  if ((slot < 0) || (slot > 9)) {
    fprintf(stderr, "Usage: %s <queue.dat> <slot 0-9>\n", argv[0]);
    return EXIT_FAILURE;
  }
  fd = open(argv[1], O_RDONLY);
  if (fd == -1) {
    perror("Failed to open queue.dat");
    return EXIT_FAILURE;
  }
  addr = mmap(NULL, 7168, PROT_READ, MAP_PRIVATE, fd, 0);
  if (addr == MAP_FAILED) {
    perror("Failed to map file");
    return EXIT_FAILURE;
  }
  stat = addr + 8;
  stat += (712 * slot);
  printf("%d\n", *stat);
  (void)munmap(addr, 7168);
  close(fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11cd <main+0x4d>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1310 <main+0x190>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     11f1 <main+0x71>
cmpl   $0x9,-0x28(%rbp)
jle    121e <main+0x9e>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf8(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1310 <main+0x190>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2db3(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    125e <main+0xde>
lea    0xdda(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1310 <main+0x190>
mov    0x2d93(%rip),%rax
mov    (%rax),%edx
mov    0x2d4a(%rip),%rax
mov    (%rax),%ecx
mov    -0x24(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1c00,%esi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2d1c(%rip),%rcx
cmp    (%rcx),%rax
jne    12ba <main+0x13a>
lea    0xd97(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1310 <main+0x190>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
imul   $0x2c8,-0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
lea    0xd68(%rip),%rdi
movsbl (%rax),%esi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1c00,%esi
call   1070 <munmap@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    0x2cb5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    119a <main+0x1a>
mov    0x10(%rbx),%rdi
call   10a0 <atoi@plt>
cmp    $0xa,%eax
jb     11be <main+0x3e>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe53(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e0f(%rip),%rax
jmp    1243 <main+0xc3>
mov    %eax,%ebp
mov    0x8(%rbx),%rdi
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     124a <main+0xca>
mov    %eax,%r14d
mov    0x2e17(%rip),%rax
mov    (%rax),%edx
mov    0x2dce(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x1c00,%esi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
mov    0x2da8(%rip),%rax
cmp    (%rax),%rbx
je     1253 <main+0xd3>
mov    %ebp,%eax
imul   $0x2c8,%rax,%rax
movsbl 0x8(%rbx,%rax,1),%esi
lea    0xe2c(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1c00,%esi
call   1070 <munmap@plt>
mov    %r14d,%edi
call   1050 <close@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdd1(%rip),%rdi
jmp    125a <main+0xda>
lea    0xde1(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d62(%rip),%rax
jmp    1243 <main+0xc3>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"Usage: %s <queue.dat> <slot 0-9>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [25 x i8] c"Failed to open queue.dat\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [19 x i8] c"Failed to map file\00"
@.str.3 = [4 x i8] c"%d\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 i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %3
br label %74
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp slt i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %19
%27 = load i32, i32* %9
%28 = icmp sgt i32 %27, 9
br i1 %28, label %29, label %36
29: ; preds = %26, %19
%30 = load i32, i32* @stderr
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %3
br label %74
36: ; preds = %26
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = load i32, i32* @O_RDONLY
%41 = call i32 @open(i8* %39, i32 %40)
store i32 %41, i32* %8
%42 = load i32, i32* %8
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %36
%45 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
store i32 %46, i32* %3
br label %74
47: ; preds = %36
%48 = load i32, i32* @PROT_READ
%49 = load i32, i32* @MAP_PRIVATE
%50 = load i32, i32* %8
%51 = call i8* @mmap(i32* null, i32 7168, i32 %48, i32 %49, i32 %50, i32 0)
store i8* %51, i8** %6
%52 = load i8*, i8** %6
%53 = load i8*, i8** @MAP_FAILED
%54 = icmp eq i8* %52, %53
br i1 %54, label %55, label %58
55: ; preds = %47
%56 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%57 = load i32, i32* @EXIT_FAILURE
store i32 %57, i32* %3
br label %74
58: ; preds = %47
%59 = load i8*, i8** %6
%60 = getelementptr inbounds i8, i8* %59, i64 8
store i8* %60, i8** %7
%61 = load i32, i32* %9
%62 = mul nsw i32 712, %61
%63 = load i8*, i8** %7
%64 = sext i32 %62 to i64
%65 = getelementptr inbounds i8, i8* %63, i64 %64
store i8* %65, i8** %7
%66 = load i8*, i8** %7
%67 = load i8, i8* %66
%68 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %67)
%69 = load i8*, i8** %6
%70 = call i32 @munmap(i8* %69, i32 7168)
%71 = load i32, i32* %8
%72 = call i32 @close(i32 %71)
%73 = load i32, i32* @EXIT_SUCCESS
store i32 %73, i32* %3
br label %74
74: ; preds = %58, %55, %44, %29, %12
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Usage: %s <queue.dat> <slot 0-9>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [25 x i8] c"Failed to open queue.dat\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [19 x i8] c"Failed to map file\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %42
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp ugt i32 %11, 9
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %1
%16 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %42
17: ; preds = %8
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = tail call i32 @open(i8* %19, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %42
25: ; preds = %17
%26 = load i32, i32* @PROT_READ
%27 = load i32, i32* @MAP_PRIVATE
%28 = tail call i8* @mmap(i32* null, i32 7168, i32 %26, i32 %27, i32 %21, i32 0)
%29 = load i8*, i8** @MAP_FAILED
%30 = icmp eq i8* %28, %29
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %42
33: ; preds = %25
%34 = getelementptr inbounds i8, i8* %28, i64 8
%35 = mul nuw nsw i32 %11, 712
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %38)
%40 = tail call i32 @munmap(i8* %28, i32 7168)
%41 = tail call i32 @close(i32 %21)
br label %42
42: ; preds = %33, %31, %23, %13, %4
%43 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_FAILURE, %13 ], [ @EXIT_FAILURE, %23 ], [ @EXIT_FAILURE, %31 ], [ @EXIT_SUCCESS, %33 ]
%44 = load i32, i32* %43
ret i32 %44
}