#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 msqid_ds {
  int dummy;
};

/* Variables and functions */
scalar_t__ EINVAL;
int /*<<< orphan*/ IPC_PRIVATE;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ IPC_STAT;
int /*<<< orphan*/ MSG_INFO;
int /*<<< orphan*/ MSG_STAT;
scalar_t__ errno;
int msgctl(int, int /*<<< orphan*/, struct msqid_ds *);
int msgget(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int, ...);
int main(void) {
  int rc, id;
  struct msqid_ds ds;
  id = msgget(IPC_PRIVATE, 0600);
  if (id < 0)
    return 77;
  printf("msgget\\(IPC_PRIVATE, 0600\\) += %d\n", id);
  if (msgctl(id, IPC_STAT, &ds))
    goto fail;
  printf("msgctl\\(%d, (IPC_64\\|)?IPC_STAT, %p\\) += 0\n", id, &ds);
  int max = msgctl(0, MSG_INFO, &ds);
  if (max < 0)
    goto fail;
  printf("msgctl\\(0, (IPC_64\\|)?MSG_INFO, %p\\) += %d\n", &ds, max);
  rc = msgctl(id, MSG_STAT, &ds);
  if (rc != id) {
    if (-1 != rc || EINVAL != errno)
      goto fail;
    printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += -1 EINVAL \\(Invalid "
           "argument\\)\n",
           id, &ds);
  } else {
    printf("msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += %d\n", id, &ds, id);
  }
  rc = 0;
done:
  if (msgctl(id, IPC_RMID, 0) < 0)
    return 1;
  printf("msgctl\\(%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    0x2e92(%rip),%rax
mov    (%rax),%edi
mov    $0x180,%esi
call   1030 <msgget@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    116b <main+0x3b>
movl   $0x4d,-0x4(%rbp)
jmp    12cd <main+0x19d>
mov    -0xc(%rbp),%esi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1050 <msgctl@plt>
cmp    $0x0,%eax
je     119f <main+0x6f>
jmp    12c1 <main+0x191>
mov    -0xc(%rbp),%esi
lea    0xe7a(%rip),%rdi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x10(%rbp),%rdx
call   1050 <msgctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11da <main+0xaa>
jmp    12c1 <main+0x191>
lea    -0x10(%rbp),%rax
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1050 <msgctl@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     125c <main+0x12c>
mov    $0xffffffff,%eax
cmp    -0x8(%rbp),%eax
jne    123d <main+0x10d>
mov    0x2d86(%rip),%rax
mov    (%rax),%rax
mov    0x2d8c(%rip),%rcx
cmp    (%rcx),%rax
je     1242 <main+0x112>
jmp    12c1 <main+0x191>
mov    -0xc(%rbp),%esi
lea    0xe2f(%rip),%rdi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1274 <main+0x144>
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%ecx
lea    0xe5b(%rip),%rdi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2d33(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <msgctl@plt>
cmp    $0x0,%eax
jge    12a5 <main+0x175>
movl   $0x1,-0x4(%rbp)
jmp    12cd <main+0x19d>
mov    -0xc(%rbp),%esi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12cd <main+0x19d>
movl   $0x1,-0x8(%rbp)
jmp    127b <main+0x14b>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
mov    $0x180,%esi
call   1030 <msgget@plt>
test   %eax,%eax
js     11ad <main+0x7d>
mov    %eax,%ebx
lea    0xea9(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1050 <msgctl@plt>
mov    $0x1,%ebp
mov    $0x1,%r15d
test   %eax,%eax
je     11bf <main+0x8f>
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <msgctl@plt>
test   %eax,%eax
js     11b2 <main+0x82>
lea    0xf52(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,%ebp
jmp    11b2 <main+0x82>
mov    $0x4d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe5d(%rip),%rdi
mov    %rsp,%r14
mov    %ebx,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
mov    %r14,%rdx
call   1050 <msgctl@plt>
mov    $0x1,%r15d
test   %eax,%eax
js     1182 <main+0x52>
mov    %rsp,%r14
lea    0xe53(%rip),%rdi
xor    %r15d,%r15d
mov    %r14d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <msgctl@plt>
cmp    %ebx,%eax
jne    123c <main+0x10c>
lea    0xe9b(%rip),%rdi
mov    %rsp,%rdx
mov    %ebx,%esi
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1182 <main+0x52>
mov    $0x1,%r15d
cmp    $0xffffffff,%eax
jne    1182 <main+0x52>
mov    0x2d5e(%rip),%rax
mov    (%rax),%rax
mov    0x2d64(%rip),%rcx
mov    $0x1,%r15d
cmp    (%rcx),%rax
jne    1182 <main+0x52>
lea    0xe09(%rip),%rdi
xor    %r15d,%r15d
mov    %rsp,%rdx
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1182 <main+0x52>

LLVM IR (-O0):
%struct.msqid_ds = type { i32 }
@IPC_PRIVATE = global i32 0
@.str = [35 x i8] c"msgget\\(IPC_PRIVATE, 0600\\) += %d\0A\00"
@IPC_STAT = global i32 0
@.str.1 = [44 x i8] c"msgctl\\(%d, (IPC_64\\|)?IPC_STAT, %p\\) += 0\0A\00"
@MSG_INFO = global i32 0
@.str.2 = [44 x i8] c"msgctl\\(0, (IPC_64\\|)?MSG_INFO, %p\\) += %d\0A\00"
@MSG_STAT = global i32 0
@EINVAL = global i64 0
@errno = global i64 0
@.str.3 = [73 x i8] c"msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += -1 EINVAL \\(Invalid argument\\)\0A\00"
@.str.4 = [45 x i8] c"msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += %d\0A\00"
@IPC_RMID = global i32 0
@.str.5 = [43 x i8] c"msgctl\\(%d, (IPC_64\\|)?IPC_RMID, 0\\) += 0\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.msqid_ds
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @IPC_PRIVATE
%7 = call i32 @msgget(i32 %6, 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 ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %3
%15 = load i32, i32* @IPC_STAT
%16 = call i32 @msgctl(i32 %14, i32 %15, %struct.msqid_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.msqid_ds* %4)
%22 = load i32, i32* @MSG_INFO
%23 = call i32 @msgctl(i32 0, i32 %22, %struct.msqid_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.msqid_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* @MSG_STAT
%33 = call i32 @msgctl(i32 %31, i32 %32, %struct.msqid_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.msqid_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.msqid_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 @msgctl(i32 %54, i32 %55, %struct.msqid_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.msqid_ds = type { i32 }
@IPC_PRIVATE = global i32 0
@.str = [35 x i8] c"msgget\\(IPC_PRIVATE, 0600\\) += %d\0A\00"
@IPC_STAT = global i32 0
@.str.1 = [44 x i8] c"msgctl\\(%d, (IPC_64\\|)?IPC_STAT, %p\\) += 0\0A\00"
@MSG_INFO = global i32 0
@.str.2 = [44 x i8] c"msgctl\\(0, (IPC_64\\|)?MSG_INFO, %p\\) += %d\0A\00"
@MSG_STAT = global i32 0
@EINVAL = global i64 0
@errno = global i64 0
@.str.3 = [73 x i8] c"msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += -1 EINVAL \\(Invalid argument\\)\0A\00"
@.str.4 = [45 x i8] c"msgctl\\(%d, (IPC_64\\|)?MSG_STAT, %p\\) += %d\0A\00"
@IPC_RMID = global i32 0
@.str.5 = [43 x i8] c"msgctl\\(%d, (IPC_64\\|)?IPC_RMID, 0\\) += 0\0A\00"
define i32 @main() {
%1 = alloca %struct.msqid_ds
%2 = bitcast %struct.msqid_ds* %1 to i8*
%3 = load i32, i32* @IPC_PRIVATE
%4 = tail call i32 @msgget(i32 %3, 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 ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %4)
%8 = load i32, i32* @IPC_STAT
%9 = call i32 @msgctl(i32 %4, i32 %8, %struct.msqid_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.msqid_ds* %1)
%13 = load i32, i32* @MSG_INFO
%14 = call i32 @msgctl(i32 0, i32 %13, %struct.msqid_ds* %1)
%15 = icmp slt i32 %14, 0
br i1 %15, label %33, label %16
16: ; preds = %11
%17 = ptrtoint %struct.msqid_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* @MSG_STAT
%21 = call i32 @msgctl(i32 %4, i32 %20, %struct.msqid_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.msqid_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.msqid_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 @msgctl(i32 %4, i32 %35, %struct.msqid_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
}