#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 */
struct shmid_ds {
  int dummy;
};

/* Variables and functions */
scalar_t__ EINVAL;
int /*<<< orphan*/ IPC_PRIVATE;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ IPC_STAT;
int /*<<< orphan*/ SHM_INFO;
int /*<<< orphan*/ SHM_STAT;
scalar_t__ errno;
int /*<<< orphan*/ printf(char *, int, ...);
int shmctl(int, int /*<<< orphan*/, struct shmid_ds *);
int shmget(int /*<<< orphan*/, int, int);
int main(void) {
  int rc, id;
  struct shmid_ds ds;
  id = shmget(IPC_PRIVATE, 1, 0600);
  if (id < 0)
    return 77;
  printf("shmget\\(IPC_PRIVATE, 1, 0600\\) += %d\n", id);
  if (shmctl(id, IPC_STAT, &ds))
    goto fail;
  printf("shmctl\\(%d, (IPC_64\\|)?IPC_STAT, %p\\) += 0\n", id, &ds);
  int max = shmctl(0, SHM_INFO, &ds);
  if (max < 0)
    goto fail;
  printf("shmctl\\(0, (IPC_64\\|)?SHM_INFO, %p\\) += %d\n", &ds, max);
  rc = shmctl(id, SHM_STAT, &ds);
  if (rc != id) {
    if (-1 != rc || EINVAL != errno)
      goto fail;
    printf("shmctl\\(%d, (IPC_64\\|)?SHM_STAT, %p\\) += -1 EINVAL \\(Invalid "
           "argument\\)\n",
           id, &ds);
  } else {
    printf("shmctl\\(%d, (IPC_64\\|)?SHM_STAT, %p\\) += %d\n", id, &ds, id);
  }
  rc = 0;
done:
  if (shmctl(id, IPC_RMID, 0) < 0)
    return 1;
  printf("shmctl\\(%d, (IPC_64\\|)?IPC_RMID, 0\\) += 0\n", id);
  return rc;
fail:
  rc = 1;
  goto done;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
mov    $0x180,%edx
call   1050 <shmget@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1170 <main+0x40>
movl   $0x4d,-0x4(%rbp)
jmp    12d2 <main+0x1a2>
mov    -0xc(%rbp),%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <shmctl@plt>
cmp    $0x0,%eax
je     11a4 <main+0x74>
jmp    12c6 <main+0x196>
mov    -0xc(%rbp),%esi
lea    0xe78(%rip),%rdi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x10(%rbp),%rdx
call   1040 <shmctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11df <main+0xaf>
jmp    12c6 <main+0x196>
lea    -0x10(%rbp),%rax
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <shmctl@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     1261 <main+0x131>
mov    $0xffffffff,%eax
cmp    -0x8(%rbp),%eax
jne    1242 <main+0x112>
mov    0x2d81(%rip),%rax
mov    (%rax),%rax
mov    0x2d87(%rip),%rcx
cmp    (%rcx),%rax
je     1247 <main+0x117>
jmp    12c6 <main+0x196>
mov    -0xc(%rbp),%esi
lea    0xe2d(%rip),%rdi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1279 <main+0x149>
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%ecx
lea    0xe59(%rip),%rdi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2d2e(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <shmctl@plt>
cmp    $0x0,%eax
jge    12aa <main+0x17a>
movl   $0x1,-0x4(%rbp)
jmp    12d2 <main+0x1a2>
mov    -0xc(%rbp),%esi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12d2 <main+0x1a2>
movl   $0x1,-0x8(%rbp)
jmp    1280 <main+0x150>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%ebx
mov    $0x1,%esi
mov    $0x180,%edx
call   1050 <shmget@plt>
test   %eax,%eax
js     11b3 <main+0x83>
mov    %eax,%ebp
lea    0xe9e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1040 <shmctl@plt>
test   %eax,%eax
je     11bd <main+0x8d>
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1040 <shmctl@plt>
test   %eax,%eax
js     1239 <main+0x109>
lea    0xf4f(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    123e <main+0x10e>
mov    $0x4d,%ebx
jmp    123e <main+0x10e>
lea    0xe62(%rip),%rdi
lea    0x8(%rsp),%r14
mov    %ebp,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
mov    %r14,%rdx
call   1040 <shmctl@plt>
test   %eax,%eax
js     1184 <main+0x54>
lea    0x8(%rsp),%r14
lea    0xe5a(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1040 <shmctl@plt>
cmp    %ebp,%eax
jne    1249 <main+0x119>
lea    0xea5(%rip),%rdi
lea    0x8(%rsp),%rdx
mov    %ebp,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %ebx,%ebx
jmp    1184 <main+0x54>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
cmp    $0xffffffff,%eax
jne    1184 <main+0x54>
mov    0x2d57(%rip),%rax
mov    (%rax),%rax
mov    0x2d5d(%rip),%rcx
cmp    (%rcx),%rax
jne    1184 <main+0x54>
lea    0xe0b(%rip),%rdi
xor    %ebx,%ebx
lea    0x8(%rsp),%rdx
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1184 <main+0x54>

LLVM IR (-O0):
%struct.shmid_ds = type { i32 }
@IPC_PRIVATE = global i32 0
@.str = [38 x i8] c"shmget\\(IPC_PRIVATE, 1, 0600\\) += %d\0A\00"
@IPC_STAT = global i32 0
@.str.1 = [44 x i8] c"shmctl\\(%d, (IPC_64\\|)?IPC_STAT, %p\\) += 0\0A\00"
@SHM_INFO = global i32 0
@.str.2 = [44 x i8] c"shmctl\\(0, (IPC_64\\|)?SHM_INFO, %p\\) += %d\0A\00"
@SHM_STAT = global i32 0
@EINVAL = global i64 0
@errno = global i64 0
@.str.3 = [73 x i8] c"shmctl\\(%d, (IPC_64\\|)?SHM_STAT, %p\\) += -1 EINVAL \\(Invalid argument\\)\0A\00"
@.str.4 = [45 x i8] c"shmctl\\(%d, (IPC_64\\|)?SHM_STAT, %p\\) += %d\0A\00"
@IPC_RMID = global i32 0
@.str.5 = [43 x i8] c"shmctl\\(%d, (IPC_64\\|)?IPC_RMID, 0\\) += 0\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.shmid_ds
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @IPC_PRIVATE
%7 = call i32 @shmget(i32 %6, i32 1, i32 384)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 77, i32* %1
br label %64
11: ; preds = %0
%12 = load i32, i32* %3
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %3
%15 = load i32, i32* @IPC_STAT
%16 = call i32 @shmctl(i32 %14, i32 %15, %struct.shmid_ds* %4)
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %11
br label %63
19: ; preds = %11
%20 = load i32, i32* %3
%21 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %20, %struct.shmid_ds* %4)
%22 = load i32, i32* @SHM_INFO
%23 = call i32 @shmctl(i32 0, i32 %22, %struct.shmid_ds* %4)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %19
br label %63
27: ; preds = %19
%28 = ptrtoint %struct.shmid_ds* %4 to i32
%29 = load i32, i32* %5
%30 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %29)
%31 = load i32, i32* %3
%32 = load i32, i32* @SHM_STAT
%33 = call i32 @shmctl(i32 %31, i32 %32, %struct.shmid_ds* %4)
store i32 %33, i32* %2
%34 = load i32, i32* %2
%35 = load i32, i32* %3
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %48
37: ; preds = %27
%38 = load i32, i32* %2
%39 = icmp ne i32 -1, %38
br i1 %39, label %44, label %40
40: ; preds = %37
%41 = load i64, i64* @EINVAL
%42 = load i64, i64* @errno
%43 = icmp ne i64 %41, %42
br i1 %43, label %44, label %45
44: ; preds = %40, %37
br label %63
45: ; preds = %40
%46 = load i32, i32* %3
%47 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.3, i64 0, i64 0), i32 %46, %struct.shmid_ds* %4)
br label %52
48: ; preds = %27
%49 = load i32, i32* %3
%50 = load i32, i32* %3
%51 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i32 %49, %struct.shmid_ds* %4, i32 %50)
br label %52
52: ; preds = %48, %45
store i32 0, i32* %2
br label %53
53: ; preds = %63, %52
%54 = load i32, i32* %3
%55 = load i32, i32* @IPC_RMID
%56 = call i32 @shmctl(i32 %54, i32 %55, %struct.shmid_ds* null)
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %53
store i32 1, i32* %1
br label %64
59: ; preds = %53
%60 = load i32, i32* %3
%61 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %60)
%62 = load i32, i32* %2
store i32 %62, i32* %1
br label %64
63: ; preds = %44, %26, %18
store i32 1, i32* %2
br label %53
64: ; preds = %59, %58, %10
%65 = load i32, i32* %1
ret i32 %65
}

LLVM IR (-O2):
%struct.shmid_ds = type { i32 }
@IPC_PRIVATE = global i32 0
@.str = [38 x i8] c"shmget\\(IPC_PRIVATE, 1, 0600\\) += %d\0A\00"
@IPC_STAT = global i32 0
@.str.1 = [44 x i8] c"shmctl\\(%d, (IPC_64\\|)?IPC_STAT, %p\\) += 0\0A\00"
@SHM_INFO = global i32 0
@.str.2 = [44 x i8] c"shmctl\\(0, (IPC_64\\|)?SHM_INFO, %p\\) += %d\0A\00"
@SHM_STAT = global i32 0
@EINVAL = global i64 0
@errno = global i64 0
@.str.3 = [73 x i8] c"shmctl\\(%d, (IPC_64\\|)?SHM_STAT, %p\\) += -1 EINVAL \\(Invalid argument\\)\0A\00"
@.str.4 = [45 x i8] c"shmctl\\(%d, (IPC_64\\|)?SHM_STAT, %p\\) += %d\0A\00"
@IPC_RMID = global i32 0
@.str.5 = [43 x i8] c"shmctl\\(%d, (IPC_64\\|)?IPC_RMID, 0\\) += 0\0A\00"
define i32 @main() {
%1 = alloca %struct.shmid_ds
%2 = bitcast %struct.shmid_ds* %1 to i8*
%3 = load i32, i32* @IPC_PRIVATE
%4 = tail call i32 @shmget(i32 %3, i32 1, i32 384)
%5 = icmp slt i32 %4, 0
br i1 %5, label %40, label %6
6: ; preds = %0
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %4)
%8 = load i32, i32* @IPC_STAT
%9 = call i32 @shmctl(i32 %4, i32 %8, %struct.shmid_ds* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %33
11: ; preds = %6
%12 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %4, %struct.shmid_ds* %1)
%13 = load i32, i32* @SHM_INFO
%14 = call i32 @shmctl(i32 0, i32 %13, %struct.shmid_ds* %1)
%15 = icmp slt i32 %14, 0
br i1 %15, label %33, label %16
16: ; preds = %11
%17 = ptrtoint %struct.shmid_ds* %1 to i64
%18 = trunc i64 %17 to i32
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %14)
%20 = load i32, i32* @SHM_STAT
%21 = call i32 @shmctl(i32 %4, i32 %20, %struct.shmid_ds* %1)
%22 = icmp eq i32 %21, %4
br i1 %22, label %31, label %23
23: ; preds = %16
%24 = icmp eq i32 %21, -1
br i1 %24, label %25, label %33
25: ; preds = %23
%26 = load i64, i64* @EINVAL
%27 = load i64, i64* @errno
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.3, i64 0, i64 0), i32 %4, %struct.shmid_ds* %1)
br label %33
31: ; preds = %16
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i32 %4, %struct.shmid_ds* %1, i32 %4)
br label %33
33: ; preds = %6, %11, %25, %23, %29, %31
%34 = phi i32 [ 0, %31 ], [ 0, %29 ], [ 1, %23 ], [ 1, %25 ], [ 1, %11 ], [ 1, %6 ]
%35 = load i32, i32* @IPC_RMID
%36 = call i32 @shmctl(i32 %4, i32 %35, %struct.shmid_ds* null)
%37 = icmp slt i32 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %33
%39 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %4)
br label %40
40: ; preds = %33, %0, %38
%41 = phi i32 [ %34, %38 ], [ 77, %0 ], [ 1, %33 ]
ret i32 %41
}