#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*/ test_msg(char *, char *, int, 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\n"
             " (errno = %d)\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/OSLL/pmover/refs/heads/master/test/"
             "zdtm/live/static/shm.c",
             52, -errno, 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    118d <get_shm_seg+0x6d>
xor    %ecx,%ecx
mov    0x2e83(%rip),%rax
sub    (%rax),%ecx
mov    0x2e7a(%rip),%rax
mov    (%rax),%r8d
lea    0xe90(%rip),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x34,%edx
call   1030 <test_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1193 <get_shm_seg+0x73>
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   %rbx
or     $0x1ff,%edx
call   1040 <shmget@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    115a <get_shm_seg+0x3a>
mov    0x2ea6(%rip),%rax
mov    (%rax),%r8d
mov    %r8d,%ecx
neg    %ecx
lea    0xeb7(%rip),%rdi
lea    0xedd(%rip),%rsi
mov    $0x34,%edx
call   1030 <test_msg@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [45 x i8] c"ERR: %s:%d: Can't get shm: %d\0A (errno = %d)\0A\00"
@.str.1 = [148 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/OSLL/pmover/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 %21
16: ; preds = %3
%17 = load i32, i32* @errno
%18 = sub nsw i32 0, %17
%19 = load i32, i32* @errno
%20 = call i32 @test_msg(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 52, i32 %18, i32 %19)
store i32 -1, i32* %4
br label %23
21: ; preds = %3
%22 = load i32, i32* %8
store i32 %22, i32* %4
br label %23
23: ; preds = %21, %16
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
@.str = [45 x i8] c"ERR: %s:%d: Can't get shm: %d\0A (errno = %d)\0A\00"
@.str.1 = [148 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/OSLL/pmover/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 %11
7: ; preds = %3
%8 = load i32, i32* @errno
%9 = sub nsw i32 0, %8
%10 = tail call i32 @test_msg(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 52, i32 %9, i32 %8)
br label %11
11: ; preds = %3, %7
ret i32 %5
}