#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 */
typedef struct _msgbuf TYPE_1__;

/* Type definitions */
struct _msgbuf {
  long mtype;
  char *mtext;
};

/* Variables and functions */
int msgget(int, int);
int msgrcv(int, TYPE_1__ *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int msgid, result;
  struct _msgbuf {
    long mtype;
    char mtext[2];
  } msgbuf;
  msgid = msgget(0xABC, 0666);
  if (msgid == -1) {
    perror("Couldn't find msg queue:");
    return 1;
  }
  printf("About to get message \n");
  result = msgrcv(msgid, &msgbuf, 2, 1, 0);
  if (result == -1) {
    perror("Couldn't send a message:");
    return 1;
  }
  printf("Got message %c%c\n", msgbuf.mtext[0], msgbuf.mtext[1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xabc,%edi
mov    $0x1b6,%esi
call   1030 <msgget@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1183 <main+0x43>
lea    0xe8e(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ec <main+0xac>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x2,%edx
mov    $0x1,%ecx
xor    %r8d,%r8d
call   1060 <msgrcv@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11cf <main+0x8f>
lea    0xe72(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ec <main+0xac>
movsbl -0x18(%rbp),%esi
movsbl -0x17(%rbp),%edx
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    $0xabc,%edi
mov    $0x1b6,%esi
call   1030 <msgget@plt>
cmp    $0xffffffff,%eax
je     11be <main+0x6e>
mov    %eax,%ebp
lea    0xed1(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rsi
mov    $0x1,%ebx
mov    %ebp,%edi
mov    $0x2,%edx
mov    $0x1,%ecx
xor    %r8d,%r8d
call   1070 <msgrcv@plt>
cmp    $0xffffffff,%eax
je     11d1 <main+0x81>
movsbl 0x10(%rsp),%esi
movsbl 0x11(%rsp),%edx
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe3b(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%ebx
jmp    11b5 <main+0x65>
lea    0xe41(%rip),%rdi
call   1060 <perror@plt>
jmp    11b5 <main+0x65>

LLVM IR (-O0):
%struct._msgbuf = type { i64, [2 x i8] }
%struct._msgbuf.0 = type { i64, i8* }
@.str = [25 x i8] c"Couldn't find msg queue:\00"
@.str.1 = [23 x i8] c"About to get message \0A\00"
@.str.2 = [25 x i8] c"Couldn't send a message:\00"
@.str.3 = [18 x i8] c"Got message %c%c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct._msgbuf
store i32 0, i32* %1
%5 = call i32 @msgget(i32 2748, i32 438)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %29
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* %2
%13 = bitcast %struct._msgbuf* %4 to %struct._msgbuf.0*
%14 = call i32 @msgrcv(i32 %12, %struct._msgbuf.0* %13, i32 2, i32 1, i32 0)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %29
19: ; preds = %10
%20 = getelementptr inbounds %struct._msgbuf, %struct._msgbuf* %4, i32 0, i32 1
%21 = getelementptr inbounds [2 x i8], [2 x i8]* %20, i64 0, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = getelementptr inbounds %struct._msgbuf, %struct._msgbuf* %4, i32 0, i32 1
%25 = getelementptr inbounds [2 x i8], [2 x i8]* %24, i64 0, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 %27)
store i32 0, i32* %1
br label %29
29: ; preds = %19, %17, %8
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
%struct._msgbuf = type { i64, [2 x i8] }
%struct._msgbuf.0 = type { i64, i8* }
@.str = [25 x i8] c"Couldn't find msg queue:\00"
@.str.2 = [25 x i8] c"Couldn't send a message:\00"
@.str.3 = [18 x i8] c"Got message %c%c\0A\00"
@str = [22 x i8] c"About to get message \00"
define i32 @main() {
%1 = alloca %struct._msgbuf
%2 = bitcast %struct._msgbuf* %1 to i8*
%3 = tail call i32 @msgget(i32 2748, i32 438)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %22
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%9 = bitcast %struct._msgbuf* %1 to %struct._msgbuf.0*
%10 = call i32 @msgrcv(i32 %3, %struct._msgbuf.0* %9, i32 2, i32 1, i32 0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %22
14: ; preds = %7
%15 = getelementptr inbounds %struct._msgbuf, %struct._msgbuf* %1, i64 0, i32 1, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = getelementptr inbounds %struct._msgbuf, %struct._msgbuf* %1, i64 0, i32 1, i64 1
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %17, i32 %20)
br label %22
22: ; preds = %14, %12, %5
%23 = phi i32 [ 1, %5 ], [ 1, %12 ], [ 0, %14 ]
ret i32 %23
}