#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 /*<<< orphan*/ errno;
int shmget(int, size_t, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ test_msg(char *, char *, int, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/);
int get_shm_seg(int key, size_t size, unsigned int flags) {
  int id;
  id = shmget(key, size, 0777 | flags);
  if (id == -1) {
    test_msg("ERR: %s:%d: "
             "Can't get shm: %d"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/"
             "master/test/zdtm/live/static/shm.c",
             52, -errno, errno, strerror(errno));
    return -1;
  }
  return id;
}


x86 assembly (clang, -O0):
<get_shm_seg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
or     $0x1ff,%edx
call   1040 <shmget@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11ba <get_shm_seg+0x8a>
xor    %eax,%eax
mov    0x2e73(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    %eax,%r9d
lea    0xe63(%rip),%rdi
lea    0xe8d(%rip),%rsi
mov    $0x34,%edx
call   1030 <test_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c0 <get_shm_seg+0x90>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_shm_seg>:
push   %rbp
push   %r14
push   %rbx
or     $0x1ff,%edx
call   1040 <shmget@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    117d <get_shm_seg+0x4d>
mov    0x2e93(%rip),%rax
mov    (%rax),%r14d
mov    %r14d,%ebp
neg    %ebp
mov    %r14d,%edi
call   1050 <strerror@plt>
lea    0xe9c(%rip),%rdi
lea    0xec6(%rip),%rsi
mov    $0x34,%edx
mov    %ebp,%ecx
mov    %r14d,%r8d
mov    %eax,%r9d
call   1030 <test_msg@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"ERR: %s:%d: Can't get shm: %d (errno = %d (%s))\0A\00"
@.str.1 = [160 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/master/test/zdtm/live/static/shm.c\00"
@errno = global i32 0
define i32 @get_shm_seg(i32 %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
%10 = load i64, i64* %6
%11 = load i32, i32* %7
%12 = or i32 511, %11
%13 = call i32 @shmget(i32 %9, i64 %10, i32 %12)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %23
16: ; preds = %3
%17 = load i32, i32* @errno
%18 = sub nsw i32 0, %17
%19 = load i32, i32* @errno
%20 = load i32, i32* @errno
%21 = call i32 @strerror(i32 %20)
%22 = call i32 @test_msg(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.1, i64 0, i64 0), i32 52, i32 %18, i32 %19, i32 %21)
store i32 -1, i32* %4
br label %25
23: ; preds = %3
%24 = load i32, i32* %8
store i32 %24, i32* %4
br label %25
25: ; preds = %23, %16
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
@.str = [49 x i8] c"ERR: %s:%d: Can't get shm: %d (errno = %d (%s))\0A\00"
@.str.1 = [160 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/master/test/zdtm/live/static/shm.c\00"
@errno = global i32 0
define i32 @get_shm_seg(i32 %0, i64 %1, i32 %2) {
%4 = or i32 %2, 511
%5 = tail call i32 @shmget(i32 %0, i64 %1, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = load i32, i32* @errno
%9 = sub nsw i32 0, %8
%10 = tail call i32 @strerror(i32 %8)
%11 = tail call i32 @test_msg(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([160 x i8], [160 x i8]* @.str.1, i64 0, i64 0), i32 52, i32 %9, i32 %8, i32 %10)
br label %12
12: ; preds = %3, %7
ret i32 %5
}