#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 /*<<< orphan*/ IPC_PRIVATE;
int /*<<< orphan*/ IPC_RMID;
int __chk_error(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ error1(char *, int, char *);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
void *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ shmdt(void *);
int /*<<< orphan*/ shmget(int /*<<< orphan*/, int, int);
void test_shm(void) {
  void *ptr;
  int shmid;
  shmid = __chk_error(
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/Chilledheart/vbox/refs/heads/master/"
      "VirtualBox-5.0.0/src/recompiler/tests/linux-test.c",
      524, (shmget(IPC_PRIVATE, 32768, IPC_CREAT | 0777)));
  ptr = shmat(shmid, NULL, 0);
  if (!ptr)
    error1("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/Chilledheart/vbox/refs/heads/master/"
           "VirtualBox-5.0.0/src/recompiler/tests/linux-test.c",
           527, "shmat");
  memset(ptr, 0, 32768);
  __chk_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/Chilledheart/vbox/refs/heads/master/"
              "VirtualBox-5.0.0/src/recompiler/tests/linux-test.c",
              531, (shmctl(shmid, IPC_RMID, 0)));
  __chk_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/Chilledheart/vbox/refs/heads/master/"
              "VirtualBox-5.0.0/src/recompiler/tests/linux-test.c",
              532, (shmdt(ptr)));
}


x86 assembly (clang, -O0):
<test_shm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
or     $0x1ff,%edx
mov    $0x8000,%esi
call   1080 <shmget@plt>
mov    %eax,%edx
lea    0xe5d(%rip),%rdi
mov    $0x20c,%esi
call   1040 <__chk_error@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <shmat@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11e5 <test_shm+0x75>
lea    0xe2c(%rip),%rdi
mov    $0x20f,%esi
lea    0xed1(%rip),%rdx
call   1090 <error1@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x8000,%edx
call   1050 <memset@plt>
mov    -0xc(%rbp),%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <shmctl@plt>
mov    %eax,%edx
lea    0xdef(%rip),%rdi
mov    $0x213,%esi
call   1040 <__chk_error@plt>
mov    -0x8(%rbp),%rdi
call   1030 <shmdt@plt>
mov    %eax,%edx
lea    0xdd3(%rip),%rdi
mov    $0x214,%esi
call   1040 <__chk_error@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_shm>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    0x2e4d(%rip),%rax
mov    $0x1ff,%edx
or     (%rax),%edx
mov    $0x8000,%esi
call   1080 <shmget@plt>
lea    0xe65(%rip),%rdi
mov    $0x20c,%esi
mov    %eax,%edx
call   1040 <__chk_error@plt>
mov    %eax,%ebp
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <shmat@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11d4 <test_shm+0x64>
lea    0xe3d(%rip),%rdi
lea    0xee7(%rip),%rdx
mov    $0x20f,%esi
call   1090 <error1@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8000,%edx
call   1050 <memset@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1060 <shmctl@plt>
lea    0xe04(%rip),%rbp
mov    %rbp,%rdi
mov    $0x213,%esi
mov    %eax,%edx
call   1040 <__chk_error@plt>
mov    %rbx,%rdi
call   1030 <shmdt@plt>
mov    %rbp,%rdi
mov    $0x214,%esi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <__chk_error@plt>

LLVM IR (-O0):
@.str = [177 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Chilledheart/vbox/refs/heads/master/VirtualBox-5.0.0/src/recompiler/tests/linux-test.c\00"
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@.str.1 = [6 x i8] c"shmat\00"
@IPC_RMID = global i32 0
define void @test_shm() {
%1 = alloca i8*
%2 = alloca i32
%3 = load i32, i32* @IPC_PRIVATE
%4 = load i32, i32* @IPC_CREAT
%5 = or i32 %4, 511
%6 = call i32 @shmget(i32 %3, i32 32768, i32 %5)
%7 = call i32 @__chk_error(i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str, i64 0, i64 0), i32 524, i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = call i8* @shmat(i32 %8, i32* null, i32 0)
store i8* %9, i8** %1
%10 = load i8*, i8** %1
%11 = icmp ne i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %0
%13 = call i32 @error1(i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str, i64 0, i64 0), i32 527, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %0
%15 = load i8*, i8** %1
%16 = call i32 @memset(i8* %15, i32 0, i32 32768)
%17 = load i32, i32* %2
%18 = load i32, i32* @IPC_RMID
%19 = call i32 @shmctl(i32 %17, i32 %18, i32 0)
%20 = call i32 @__chk_error(i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str, i64 0, i64 0), i32 531, i32 %19)
%21 = load i8*, i8** %1
%22 = call i32 @shmdt(i8* %21)
%23 = call i32 @__chk_error(i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str, i64 0, i64 0), i32 532, i32 %22)
ret void
}

LLVM IR (-O2):
@.str = [177 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Chilledheart/vbox/refs/heads/master/VirtualBox-5.0.0/src/recompiler/tests/linux-test.c\00"
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@.str.1 = [6 x i8] c"shmat\00"
@IPC_RMID = global i32 0
define void @test_shm() {
%1 = load i32, i32* @IPC_PRIVATE
%2 = load i32, i32* @IPC_CREAT
%3 = or i32 %2, 511
%4 = tail call i32 @shmget(i32 %1, i32 32768, i32 %3)
%5 = tail call i32 @__chk_error(i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str, i64 0, i64 0), i32 524, i32 %4)
%6 = tail call i8* @shmat(i32 %5, i32* null, i32 0)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @error1(i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str, i64 0, i64 0), i32 527, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = tail call i32 @memset(i8* %6, i32 0, i32 32768)
%12 = load i32, i32* @IPC_RMID
%13 = tail call i32 @shmctl(i32 %5, i32 %12, i32 0)
%14 = tail call i32 @__chk_error(i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str, i64 0, i64 0), i32 531, i32 %13)
%15 = tail call i32 @shmdt(i8* %6)
%16 = tail call i32 @__chk_error(i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str, i64 0, i64 0), i32 532, i32 %15)
ret void
}