#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 */
char *getenv(char *);
scalar_t__ sbrk(int /*<<< orphan*/);
scalar_t__ strtol(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
char *shared_mem_base(void) {
  char *base, *env_shmbase;
  env_shmbase = getenv("ECLIPSE_SHMBASE");
  if (env_shmbase) {
    base = (char *)strtol(env_shmbase, 0, 0);
  } else {
    base = (char *)0x20000000;
  }
  if (base && (char *)sbrk(0) + 16 * 1048576 >= base) {
    (void)write(2, "ECLiPSe: bad memory layout\n", 27);
  }
  return base;
}


x86 assembly (clang, -O0):
<shared_mem_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1179 <shared_mem_base+0x39>
mov    -0x10(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1060 <strtol@plt>
mov    %rax,-0x8(%rbp)
jmp    1182 <shared_mem_base+0x42>
mov    $0x20000000,%eax
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ba <shared_mem_base+0x7a>
xor    %edi,%edi
call   1050 <sbrk@plt>
add    $0x1000000,%rax
cmp    -0x8(%rbp),%rax
jb     11ba <shared_mem_base+0x7a>
mov    $0x2,%edi
lea    0xe60(%rip),%rsi
mov    $0x1b,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shared_mem_base>:
push   %rbx
lea    0xeb8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116a <shared_mem_base+0x2a>
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    116f <shared_mem_base+0x2f>
xor    %ebx,%ebx
jmp    1197 <shared_mem_base+0x57>
mov    $0x20000000,%ebx
xor    %edi,%edi
call   1050 <sbrk@plt>
add    $0x1000000,%rax
cmp    %rbx,%rax
jb     1197 <shared_mem_base+0x57>
lea    0xe88(%rip),%rsi
mov    $0x2,%edi
mov    $0x1b,%edx
call   1040 <write@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"ECLIPSE_SHMBASE\00"
@.str.1 = [28 x i8] c"ECLiPSe: bad memory layout\0A\00"
define i8* @shared_mem_base() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i8*, i8** %2
%8 = call i64 @strtol(i8* %7, i32 0, i32 0)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %1
br label %11
10: ; preds = %0
store i8* inttoptr (i64 536870912 to i8*), i8** %1
br label %11
11: ; preds = %10, %6
%12 = load i8*, i8** %1
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = call i64 @sbrk(i32 0)
%16 = inttoptr i64 %15 to i8*
%17 = getelementptr inbounds i8, i8* %16, i64 16777216
%18 = load i8*, i8** %1
%19 = icmp uge i8* %17, %18
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 @write(i32 2, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 27)
br label %22
22: ; preds = %20, %14, %11
%23 = load i8*, i8** %1
ret i8* %23
}

LLVM IR (-O2):
@.str = [16 x i8] c"ECLIPSE_SHMBASE\00"
@.str.1 = [28 x i8] c"ECLiPSe: bad memory layout\0A\00"
define i8* @shared_mem_base() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %7, label %3
3: ; preds = %0
%4 = tail call i64 @strtol(i8* %1, i32 0, i32 0)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %15, label %7
7: ; preds = %0, %3
%8 = phi i8* [ %5, %3 ], [ inttoptr (i64 536870912 to i8*), %0 ]
%9 = tail call i64 @sbrk(i32 0)
%10 = inttoptr i64 %9 to i8*
%11 = getelementptr inbounds i8, i8* %10, i64 16777216
%12 = icmp ult i8* %11, %8
br i1 %12, label %15, label %13
13: ; preds = %7
%14 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 27)
br label %15
15: ; preds = %13, %7, %3
%16 = phi i8* [ %8, %13 ], [ %8, %7 ], [ null, %3 ]
ret i8* %16
}