#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ mmap_read(char *, int);
int /*<<< orphan*/ mmap_write(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, int *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int nbblocks = 0;
  if (argc < 4) {
    printf(" <filename> <read|write> <blocks>\n");
    exit(EXIT_FAILURE);
  }
  if (sscanf(argv[3], "%d", &nbblocks) != 1) {
    printf("Bad block number : <filename> <read|write> <blocks>\n");
    exit(EXIT_FAILURE);
  }
  if (strcmp(argv[2], "read") == 0)
    mmap_read(argv[1], nbblocks);
  else if (strcmp(argv[2], "write") == 0)
    mmap_write(argv[1], nbblocks);
  printf("No such action %s\n", argv[2]);
  exit(EXIT_FAILURE);
}


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)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11a3 <main+0x43>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe4e(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
je     11e0 <main+0x80>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe49(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1213 <main+0xb3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x14(%rbp),%esi
call   1060 <mmap_read@plt>
jmp    1246 <main+0xe6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe1b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1241 <main+0xe1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x14(%rbp),%esi
call   1030 <mmap_write@plt>
jmp    1246 <main+0xe6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
cmp    $0x3,%edi
jg     118b <main+0x1b>
lea    0xeaa(%rip),%rdi
jmp    11d3 <main+0x63>
mov    %rsi,%rbx
mov    0x18(%rsi),%rdi
lea    0xe67(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    11cc <main+0x5c>
mov    0x10(%rbx),%rdi
lea    0xe50(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11da <main+0x6a>
mov    0x8(%rbx),%rdi
mov    0xc(%rsp),%esi
call   1070 <mmap_read@plt>
jmp    11fc <main+0x8c>
lea    0xe4e(%rip),%rdi
call   1040 <puts@plt>
jmp    120e <main+0x9e>
mov    0x10(%rbx),%rdi
lea    0xe23(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11fc <main+0x8c>
mov    0x8(%rbx),%rdi
mov    0xc(%rsp),%esi
call   1030 <mmap_write@plt>
mov    0x10(%rbx),%rsi
lea    0xe07(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [35 x i8] c" <filename> <read|write> <blocks>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [53 x i8] c"Bad block number : <filename> <read|write> <blocks>\0A\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [6 x i8] c"write\00"
@.str.5 = [19 x i8] c"No such action %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 4
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 3
%16 = load i8*, i8** %15
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%18 = icmp ne i32 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %13
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %23
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i32, i32* %6
%34 = call i32 @mmap_read(i8* %32, i32 %33)
br label %48
35: ; preds = %23
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %35
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = load i32, i32* %6
%46 = call i32 @mmap_write(i8* %44, i32 %45)
br label %47
47: ; preds = %41, %35
br label %48
48: ; preds = %47, %29
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %51)
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [6 x i8] c"write\00"
@.str.5 = [19 x i8] c"No such action %s\0A\00"
@str = [52 x i8] c"Bad block number : <filename> <read|write> <blocks>\00"
@str.6 = [34 x i8] c" <filename> <read|write> <blocks>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = icmp slt i32 %0, 4
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.6, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 3
%12 = load i8*, i8** %11
%13 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%14 = icmp eq i32 %13, 1
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %10
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = load i32, i32* %3
%28 = call i32 @mmap_read(i8* %26, i32 %27)
br label %38
29: ; preds = %19
%30 = load i8*, i8** %20
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = getelementptr inbounds i8*, i8** %1, i64 1
%35 = load i8*, i8** %34
%36 = load i32, i32* %3
%37 = call i32 @mmap_write(i8* %35, i32 %36)
br label %38
38: ; preds = %29, %33, %24
%39 = load i8*, i8** %20
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
}