#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_ANONYMOUS;
int MAP_FIXED;
int PROT_READ;
int PROT_WRITE;
void *mmap(void *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, int);
void tst_const_addr(void) {
  void *addr = mmap((void *)0x20000000, 4096, PROT_READ | PROT_WRITE,
                    MAP_FIXED | MAP_ANONYMOUS, -1, 0);
  if (addr != (void *)-1) {
    *(int *)0x20000000 += 42;
    munmap(addr, 4096);
  }
}


x86 assembly (clang, -O0):
<tst_const_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ec9(%rip),%rax
mov    (%rax),%edx
mov    0x2e98(%rip),%rax
or     (%rax),%edx
mov    0x2e87(%rip),%rax
mov    (%rax),%ecx
mov    0x2e96(%rip),%rax
or     (%rax),%ecx
mov    $0x20000000,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x8(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x8(%rbp)
je     1198 <tst_const_addr+0x78>
mov    $0x20000000,%eax
mov    (%rax),%ecx
add    $0x2a,%ecx
mov    $0x20000000,%eax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x1000,%esi
call   1040 <munmap@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tst_const_addr>:
push   %rax
mov    0x2ed0(%rip),%rax
mov    0x2ea1(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e8e(%rip),%rax
mov    0x2e9f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    $0x20000000,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     1179 <tst_const_addr+0x59>
addl   $0x2a,0x20000000
2a
mov    %rax,%rdi
mov    $0x1000,%esi
pop    %rax
jmp    1040 <munmap@plt>
pop    %rax
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_FIXED = global i32 0
@MAP_ANONYMOUS = global i32 0
define void @tst_const_addr() {
%1 = alloca i8*
%2 = load i32, i32* @PROT_READ
%3 = load i32, i32* @PROT_WRITE
%4 = or i32 %2, %3
%5 = load i32, i32* @MAP_FIXED
%6 = load i32, i32* @MAP_ANONYMOUS
%7 = or i32 %5, %6
%8 = call i8* @mmap(i8* inttoptr (i64 536870912 to i8*), i32 4096, i32 %4, i32 %7, i32 -1, i32 0)
store i8* %8, i8** %1
%9 = load i8*, i8** %1
%10 = icmp ne i8* %9, inttoptr (i64 -1 to i8*)
br i1 %10, label %11, label %16
11: ; preds = %0
%12 = load i32, i32* inttoptr (i64 536870912 to i32*)
%13 = add nsw i32 %12, 42
store i32 %13, i32* inttoptr (i64 536870912 to i32*)
%14 = load i8*, i8** %1
%15 = call i32 @munmap(i8* %14, i32 4096)
br label %16
16: ; preds = %11, %0
ret void
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_FIXED = global i32 0
@MAP_ANONYMOUS = global i32 0
define void @tst_const_addr() {
%1 = load i32, i32* @PROT_READ
%2 = load i32, i32* @PROT_WRITE
%3 = or i32 %2, %1
%4 = load i32, i32* @MAP_FIXED
%5 = load i32, i32* @MAP_ANONYMOUS
%6 = or i32 %5, %4
%7 = tail call i8* @mmap(i8* inttoptr (i64 536870912 to i8*), i32 4096, i32 %3, i32 %6, i32 -1, i32 0)
%8 = icmp eq i8* %7, inttoptr (i64 -1 to i8*)
br i1 %8, label %13, label %9
9: ; preds = %0
%10 = load i32, i32* inttoptr (i64 536870912 to i32*)
%11 = add nsw i32 %10, 42
store i32 %11, i32* inttoptr (i64 536870912 to i32*)
%12 = tail call i32 @munmap(i8* %7, i32 4096)
br label %13
13: ; preds = %9, %0
ret void
}