#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 MAP_ANON;
void *MAP_FAILED;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ foo(unsigned short *, unsigned short *);
void *mmap(void *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int main(void) {
  void *x;
  size_t b_offset;
  x = mmap((void *)0x1122000000, 0x10000, PROT_READ | PROT_WRITE,
           MAP_PRIVATE | MAP_ANON, -1, 0);
  if (x == MAP_FAILED) {
    perror("mmap");
    return 1;
  }
  b_offset = 0x10000 - (2 * 320 - 1) * sizeof(unsigned short);
  foo((unsigned short *)x, (unsigned short *)((char *)x + b_offset));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%edx
mov    0x2e89(%rip),%rax
or     (%rax),%edx
mov    0x2e70(%rip),%rax
mov    (%rax),%ecx
mov    0x2e6f(%rip),%rax
or     (%rax),%ecx
movabs $0x1122000000,%rdi
mov    $0x10000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%rax
jne    11b0 <main+0x80>
lea    0xe61(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d0 <main+0xa0>
movq   $0xfb02,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    -0x18(%rbp),%rsi
call   1040 <foo@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ec0(%rip),%rax
mov    0x2e99(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e7e(%rip),%rax
mov    0x2e7f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
movabs $0x1122000000,%rdi
xor    %ebx,%ebx
mov    $0x10000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    0x2e45(%rip),%rcx
cmp    (%rcx),%rax
je     1196 <main+0x66>
mov    %rax,%rsi
add    $0xfb02,%rsi
mov    %rax,%rdi
call   1040 <foo@plt>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe63(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%ebx
jmp    1192 <main+0x62>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANON = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
store i32 0, i32* %1
%4 = load i32, i32* @PROT_READ
%5 = load i32, i32* @PROT_WRITE
%6 = or i32 %4, %5
%7 = load i32, i32* @MAP_PRIVATE
%8 = load i32, i32* @MAP_ANON
%9 = or i32 %7, %8
%10 = call i8* @mmap(i8* inttoptr (i64 73584869376 to i8*), i32 65536, i32 %6, i32 %9, i32 -1, i32 0)
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = load i8*, i8** @MAP_FAILED
%13 = icmp eq i8* %11, %12
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %24
16: ; preds = %0
store i64 64258, i64* %3
%17 = load i8*, i8** %2
%18 = bitcast i8* %17 to i16*
%19 = load i8*, i8** %2
%20 = load i64, i64* %3
%21 = getelementptr inbounds i8, i8* %19, i64 %20
%22 = bitcast i8* %21 to i16*
%23 = call i32 @foo(i16* %18, i16* %22)
store i32 0, i32* %1
br label %24
24: ; preds = %16, %14
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANON = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
define i32 @main() {
%1 = load i32, i32* @PROT_READ
%2 = load i32, i32* @PROT_WRITE
%3 = or i32 %2, %1
%4 = load i32, i32* @MAP_PRIVATE
%5 = load i32, i32* @MAP_ANON
%6 = or i32 %5, %4
%7 = tail call i8* @mmap(i8* inttoptr (i64 73584869376 to i8*), i32 65536, i32 %3, i32 %6, i32 -1, i32 0)
%8 = load i8*, i8** @MAP_FAILED
%9 = icmp eq i8* %7, %8
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %17
12: ; preds = %0
%13 = bitcast i8* %7 to i16*
%14 = getelementptr inbounds i8, i8* %7, i64 64258
%15 = bitcast i8* %14 to i16*
%16 = tail call i32 @foo(i16* %13, i16* %15)
br label %17
17: ; preds = %12, %10
%18 = phi i32 [ 1, %10 ], [ 0, %12 ]
ret i32 %18
}