#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 IPC_CREAT;
int IPC_EXCL;
int /*<<< orphan*/ IPC_PRIVATE;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ assert(int);
void *mremap(void *, int, int, int /*<<< orphan*/);
void *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmget(int /*<<< orphan*/, int, int);
int main() {
  int shmid =
      shmget(IPC_PRIVATE, 100 * 4096, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
  assert(shmid != -1);
  void *addr = shmat(shmid, NULL, 0);
  assert(addr != (void *)-1);
  addr = mremap(addr, 100 * 4096, 40 * 4096, 0);
  assert(addr != (void *)-1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
mov    0x2e88(%rip),%rax
or     (%rax),%edx
mov    0x2e57(%rip),%rax
or     (%rax),%edx
mov    0x2e5e(%rip),%rax
or     (%rax),%edx
mov    $0x64000,%esi
call   1060 <shmget@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <shmat@plt>
mov    %rax,-0x10(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    $0x64000,%esi
mov    $0x28000,%edx
xor    %ecx,%ecx
call   1040 <mremap@plt>
mov    %rax,-0x10(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e78(%rip),%rax
mov    0x2ea1(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e86(%rip),%rax
mov    0x2e67(%rip),%rcx
or     (%rcx),%edx
mov    (%rax),%edi
mov    0x2e6c(%rip),%rax
or     (%rax),%edx
mov    $0x64000,%esi
call   1060 <shmget@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1030 <assert@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <shmat@plt>
mov    %rax,%rbx
xor    %edi,%edi
cmp    $0xffffffffffffffff,%rax
setne  %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
mov    $0x64000,%esi
mov    $0x28000,%edx
xor    %ecx,%ecx
call   1040 <mremap@plt>
xor    %edi,%edi
cmp    $0xffffffffffffffff,%rax
setne  %dil
call   1030 <assert@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
%4 = load i32, i32* @IPC_PRIVATE
%5 = load i32, i32* @IPC_CREAT
%6 = load i32, i32* @IPC_EXCL
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IRUSR
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IWUSR
%11 = or i32 %9, %10
%12 = call i32 @shmget(i32 %4, i32 409600, i32 %11)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = icmp ne i32 %13, -1
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i32, i32* %2
%18 = call i8* @shmat(i32 %17, i32* null, i32 0)
store i8* %18, i8** %3
%19 = load i8*, i8** %3
%20 = icmp ne i8* %19, inttoptr (i64 -1 to i8*)
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i8*, i8** %3
%24 = call i8* @mremap(i8* %23, i32 409600, i32 163840, i32 0)
store i8* %24, i8** %3
%25 = load i8*, i8** %3
%26 = icmp ne i8* %25, inttoptr (i64 -1 to i8*)
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
ret i32 0
}

LLVM IR (-O2):
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @main() {
%1 = load i32, i32* @IPC_PRIVATE
%2 = load i32, i32* @IPC_CREAT
%3 = load i32, i32* @IPC_EXCL
%4 = or i32 %3, %2
%5 = load i32, i32* @S_IRUSR
%6 = or i32 %4, %5
%7 = load i32, i32* @S_IWUSR
%8 = or i32 %6, %7
%9 = tail call i32 @shmget(i32 %1, i32 409600, i32 %8)
%10 = icmp ne i32 %9, -1
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = tail call i8* @shmat(i32 %9, i32* null, i32 0)
%14 = icmp ne i8* %13, inttoptr (i64 -1 to i8*)
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = tail call i8* @mremap(i8* %13, i32 409600, i32 163840, i32 0)
%18 = icmp ne i8* %17, inttoptr (i64 -1 to i8*)
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
ret i32 0
}