#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 */
typedef int /*<<< orphan*/ key_t;

/* Variables and functions */
int IPC_CREAT;
int /*<<< orphan*/ child(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int msgget(int /*<<< orphan*/, int);
int /*<<< orphan*/ parent(int);
int /*<<< orphan*/ perror(char *);
int main(int argc, char **argv) {
  int msgid;
  msgid = msgget((key_t)9977, IPC_CREAT | 0666);
  if (msgid == -1) {
    perror("semget failed");
    exit(1);
  }
  if (fork() == 0) {
    child(msgid);
  } else {
    parent(msgid);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
mov    $0x26f9,%edi
call   1030 <msgget@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b2 <main+0x52>
lea    0xe5d(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%rax
jne    11d0 <main+0x70>
mov    -0x14(%rbp),%edi
call   1040 <child@plt>
jmp    11d8 <main+0x78>
mov    -0x14(%rbp),%edi
call   1050 <parent@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e78(%rip),%rax
mov    $0x1b6,%esi
or     (%rax),%esi
mov    $0x26f9,%edi
call   1030 <msgget@plt>
cmp    $0xffffffff,%eax
je     119e <main+0x3e>
mov    %eax,%ebx
xor    %eax,%eax
call   1080 <fork@plt>
mov    %ebx,%edi
test   %rax,%rax
je     1195 <main+0x35>
call   1050 <parent@plt>
jmp    119a <main+0x3a>
call   1040 <child@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe5b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@.str = [14 x i8] c"semget failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @IPC_CREAT
%8 = or i32 %7, 438
%9 = call i32 @msgget(i32 9977, i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = call i64 (...) @fork()
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* %6
%20 = call i32 @child(i32 %19)
br label %24
21: ; preds = %15
%22 = load i32, i32* %6
%23 = call i32 @parent(i32 %22)
br label %24
24: ; preds = %21, %18
ret i32 0
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str = [14 x i8] c"semget failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @IPC_CREAT
%4 = or i32 %3, 438
%5 = tail call i32 @msgget(i32 9977, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = tail call i64 (...) @fork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @child(i32 %5)
br label %17
15: ; preds = %10
%16 = tail call i32 @parent(i32 %5)
br label %17
17: ; preds = %15, %13
ret i32 0
}