#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/dslutz/qemu/refs/"
                      "heads/master/tests/tcg/multiarch/linux-test.c",
                      508, (shmget(IPC_PRIVATE, 32768, IPC_CREAT | 0777)));
  ptr = shmat(shmid, NULL, 0);
  if (ptr == (void *)-1) {
    error1("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/dslutz/qemu/refs/heads/master/tests/tcg/"
           "multiarch/linux-test.c",
           511, "shmat");
  }
  memset(ptr, 0, 32768);
  __chk_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/dslutz/qemu/refs/heads/master/tests/"
              "tcg/multiarch/linux-test.c",
              516, (shmctl(shmid, IPC_RMID, 0)));
  __chk_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/dslutz/qemu/refs/heads/master/tests/"
              "tcg/multiarch/linux-test.c",
              517, (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    $0x1fc,%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)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x8(%rbp)
jne    11eb <test_shm+0x7b>
lea    0xe26(%rip),%rdi
mov    $0x1ff,%esi
lea    0xeb3(%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    0x2dd3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <shmctl@plt>
mov    %eax,%edx
lea    0xde9(%rip),%rdi
mov    $0x204,%esi
call   1040 <__chk_error@plt>
mov    -0x8(%rbp),%rdi
call   1030 <shmdt@plt>
mov    %eax,%edx
lea    0xdcd(%rip),%rdi
mov    $0x205,%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    $0x1fc,%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
cmp    $0xffffffffffffffff,%rax
jne    11d5 <test_shm+0x65>
lea    0xe3c(%rip),%rdi
lea    0xece(%rip),%rdx
mov    $0x1ff,%esi
call   1090 <error1@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8000,%edx
call   1050 <memset@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1060 <shmctl@plt>
lea    0xe03(%rip),%rbp
mov    %rbp,%rdi
mov    $0x204,%esi
mov    %eax,%edx
call   1040 <__chk_error@plt>
mov    %rbx,%rdi
call   1030 <shmdt@plt>
mov    %rbp,%rdi
mov    $0x205,%esi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <__chk_error@plt>

LLVM IR (-O0):
@.str = [153 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dslutz/qemu/refs/heads/master/tests/tcg/multiarch/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 ([153 x i8], [153 x i8]* @.str, i64 0, i64 0), i32 508, 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 eq i8* %10, inttoptr (i64 -1 to i8*)
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @error1(i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str, i64 0, i64 0), i32 511, 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 ([153 x i8], [153 x i8]* @.str, i64 0, i64 0), i32 516, i32 %19)
%21 = load i8*, i8** %1
%22 = call i32 @shmdt(i8* %21)
%23 = call i32 @__chk_error(i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str, i64 0, i64 0), i32 517, i32 %22)
ret void
}

LLVM IR (-O2):
@.str = [153 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dslutz/qemu/refs/heads/master/tests/tcg/multiarch/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 ([153 x i8], [153 x i8]* @.str, i64 0, i64 0), i32 508, i32 %4)
%6 = tail call i8* @shmat(i32 %5, i32* null, i32 0)
%7 = icmp eq i8* %6, inttoptr (i64 -1 to i8*)
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @error1(i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str, i64 0, i64 0), i32 511, 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 ([153 x i8], [153 x i8]* @.str, i64 0, i64 0), i32 516, i32 %13)
%15 = tail call i32 @shmdt(i8* %6)
%16 = tail call i32 @__chk_error(i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str, i64 0, i64 0), i32 517, i32 %15)
ret void
}