#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ IPC_NOWAIT;
int /*<<< orphan*/ IPC_PRIVATE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memcmp(char *, char *, int);
int msgget(int /*<<< orphan*/, int);
int msgrcv(int, struct msg_s *, int, int, int /*<<< orphan*/);
int msgsnd(int, struct msg_s *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
int main() {
  int msgq = msgget(IPC_PRIVATE, 0666);
  assert(msgq != -1);
  struct msg_s {
    long mtype;
    char string[0x100];
  };
  struct msg_s msg = {.mtype = 1};
  strcpy(msg.string, "hello, world!");
  int res = msgsnd(msgq, &msg, 0x100, IPC_NOWAIT);
  if (res) {
    fprintf(stderr, "Error sending message! %s\n", strerror(errno));
    return -1;
  }
  struct msg_s rcv_msg;
  ssize_t len = msgrcv(msgq, &rcv_msg, 0x100, msg.mtype, IPC_NOWAIT);
  assert(len == 0x100);
  assert(msg.mtype == rcv_msg.mtype);
  assert(!memcmp(msg.string, rcv_msg.string, 0x100));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    $0x1b6,%esi
call   1030 <msgget@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x108,%edx
call   1050 <memset@plt>
movq   $0x1,-0x110(%rbp)
lea    -0x110(%rbp),%rdi
add    $0x8,%rdi
lea    0xe07(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    0x2de1(%rip),%rax
mov    (%rax),%ecx
mov    $0x100,%edx
call   1070 <msgsnd@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
je     126c <main+0xdc>
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x228(%rbp)
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x228(%rbp),%edi
mov    %rax,%rdx
lea    0xdb3(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1304 <main+0x174>
mov    -0x8(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    -0x110(%rbp),%rax
mov    %eax,%ecx
mov    0x2d6a(%rip),%rax
mov    (%rax),%r8d
mov    $0x100,%edx
call   10b0 <msgrcv@plt>
mov    %eax,-0x224(%rbp)
cmpl   $0x100,-0x224(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x110(%rbp),%rax
cmp    -0x220(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x110(%rbp),%rdi
add    $0x8,%rdi
lea    -0x220(%rbp),%rsi
add    $0x8,%rsi
mov    $0x100,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x210,%rsp
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    $0x1b6,%esi
call   1030 <msgget@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1070 <assert@plt>
lea    0x8(%rsp),%r14
xorps  %xmm0,%xmm0
movups %xmm0,0xf8(%rsp)
movups %xmm0,0xe8(%rsp)
movups %xmm0,0xd8(%rsp)
movups %xmm0,0xc8(%rsp)
movups %xmm0,0xb8(%rsp)
movups %xmm0,0xa8(%rsp)
movups %xmm0,0x98(%rsp)
movups %xmm0,0x88(%rsp)
movups %xmm0,0x78(%rsp)
movups %xmm0,0x68(%rsp)
movups %xmm0,0x58(%rsp)
movups %xmm0,0x48(%rsp)
movups %xmm0,0x38(%rsp)
movups %xmm0,0x28(%rsp)
movups %xmm0,0x18(%rsp)
movups %xmm0,0x8(%rsp)
movq   $0x1,(%rsp)
lea    0xdd3(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    0x2db4(%rip),%rbx
mov    (%rbx),%ecx
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x100,%edx
call   1060 <msgsnd@plt>
test   %eax,%eax
je     1280 <main+0x100>
mov    0x2d78(%rip),%rax
mov    (%rax),%ebx
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd9f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    12e5 <main+0x165>
mov    (%rsp),%ecx
mov    (%rbx),%r8d
lea    0x108(%rsp),%rsi
mov    %ebp,%edi
mov    $0x100,%edx
call   10a0 <msgrcv@plt>
xor    %edi,%edi
cmp    $0x100,%eax
sete   %dil
call   1070 <assert@plt>
mov    (%rsp),%rax
xor    %edi,%edi
cmp    0x108(%rsp),%rax
sete   %dil
call   1070 <assert@plt>
lea    0x110(%rsp),%rsi
mov    %r14,%rdi
mov    $0x100,%edx
call   1050 <memcmp@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.msg_s = type { i64, [256 x i8] }
%struct.msg_s.0 = type opaque
%struct.msg_s.1 = type opaque
@IPC_PRIVATE = global i32 0
@.str = [14 x i8] c"hello, world!\00"
@IPC_NOWAIT = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Error sending message! %s\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.msg_s
%4 = alloca i32
%5 = alloca %struct.msg_s
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @IPC_PRIVATE
%8 = call i32 @msgget(i32 %7, i32 438)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, -1
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = bitcast %struct.msg_s* %3 to i8*
%14 = bitcast i8* %13 to %struct.msg_s*
%15 = getelementptr inbounds %struct.msg_s, %struct.msg_s* %14, i32 0, i32 0
store i64 1, i64* %15
%16 = getelementptr inbounds %struct.msg_s, %struct.msg_s* %3, i32 0, i32 1
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %16, i64 0, i64 0
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* %2
%20 = bitcast %struct.msg_s* %3 to %struct.msg_s.0*
%21 = load i32, i32* @IPC_NOWAIT
%22 = call i32 @msgsnd(i32 %19, %struct.msg_s.0* %20, i32 256, i32 %21)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %0
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %28)
store i32 -1, i32* %1
br label %58
30: ; preds = %0
%31 = load i32, i32* %2
%32 = bitcast %struct.msg_s* %5 to %struct.msg_s.1*
%33 = getelementptr inbounds %struct.msg_s, %struct.msg_s* %3, i32 0, i32 0
%34 = load i64, i64* %33
%35 = trunc i64 %34 to i32
%36 = load i32, i32* @IPC_NOWAIT
%37 = call i32 @msgrcv(i32 %31, %struct.msg_s.1* %32, i32 256, i32 %35, i32 %36)
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = icmp eq i32 %38, 256
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = getelementptr inbounds %struct.msg_s, %struct.msg_s* %3, i32 0, i32 0
%43 = load i64, i64* %42
%44 = getelementptr inbounds %struct.msg_s, %struct.msg_s* %5, i32 0, i32 0
%45 = load i64, i64* %44
%46 = icmp eq i64 %43, %45
%47 = zext i1 %46 to i32
%48 = call i32 @assert(i32 %47)
%49 = getelementptr inbounds %struct.msg_s, %struct.msg_s* %3, i32 0, i32 1
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %49, i64 0, i64 0
%51 = getelementptr inbounds %struct.msg_s, %struct.msg_s* %5, i32 0, i32 1
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %51, i64 0, i64 0
%53 = call i32 @memcmp(i8* %50, i8* %52, i32 256)
%54 = icmp ne i32 %53, 0
%55 = xor i1 %54, true
%56 = zext i1 %55 to i32
%57 = call i32 @assert(i32 %56)
store i32 0, i32* %1
br label %58
58: ; preds = %30, %25
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
%struct.msg_s = type { i64, [256 x i8] }
%struct.msg_s.0 = type opaque
%struct.msg_s.1 = type opaque
@IPC_PRIVATE = global i32 0
@.str = [14 x i8] c"hello, world!\00"
@IPC_NOWAIT = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Error sending message! %s\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca %struct.msg_s
%2 = alloca %struct.msg_s
%3 = load i32, i32* @IPC_PRIVATE
%4 = tail call i32 @msgget(i32 %3, i32 438)
%5 = icmp ne i32 %4, -1
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = bitcast %struct.msg_s* %1 to i8*
%9 = getelementptr inbounds %struct.msg_s, %struct.msg_s* %1, i64 0, i32 1, i64 0
%10 = getelementptr inbounds %struct.msg_s, %struct.msg_s* %1, i64 0, i32 0
store i64 1, i64* %10
%11 = getelementptr inbounds %struct.msg_s, %struct.msg_s* %1, i64 0, i32 1, i64 0
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%13 = bitcast %struct.msg_s* %1 to %struct.msg_s.0*
%14 = load i32, i32* @IPC_NOWAIT
%15 = call i32 @msgsnd(i32 %4, %struct.msg_s.0* %13, i32 256, i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %0
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %43
22: ; preds = %0
%23 = bitcast %struct.msg_s* %2 to i8*
%24 = bitcast %struct.msg_s* %2 to %struct.msg_s.1*
%25 = load i64, i64* %10
%26 = trunc i64 %25 to i32
%27 = load i32, i32* @IPC_NOWAIT
%28 = call i32 @msgrcv(i32 %4, %struct.msg_s.1* %24, i32 256, i32 %26, i32 %27)
%29 = icmp eq i32 %28, 256
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load i64, i64* %10
%33 = getelementptr inbounds %struct.msg_s, %struct.msg_s* %2, i64 0, i32 0
%34 = load i64, i64* %33
%35 = icmp eq i64 %32, %34
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = getelementptr inbounds %struct.msg_s, %struct.msg_s* %2, i64 0, i32 1, i64 0
%39 = call i32 @memcmp(i8* %11, i8* %38, i32 256)
%40 = icmp eq i32 %39, 0
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
br label %43
43: ; preds = %22, %17
%44 = phi i32 [ -1, %17 ], [ 0, %22 ]
ret i32 %44
}