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

/* Variables and functions */
int EXIT_FAILURE;
int IPC_CREAT;
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ ftok(char *, int);
int msgget(int /*<<< orphan*/, int);
int msgsnd(int, void *, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int send_msg(int channel, char *text) {
  struct msgbuff {
    long mtype;
    char mtext[100];
  } message;
  int msqid;
  key_t keyx;
  struct msqid_ds msq;
  printf("processB(MessageSend)  : start\n");
  keyx = ftok("keyfilepath2", (int)'N');
  msqid = msgget(keyx, 0666 | IPC_CREAT);
  if (msqid == -1) {
    fprintf(stderr, "msgget failed with error: %d\n", errno);
    exit(EXIT_FAILURE);
  }
  printf("processB(MessageSend)   : msqID = %d\n", msqid);
  message.mtype = channel;
  strcpy(message.mtext, text);
  printf("processB(MessageSend)   : send message = %s\n", message.mtext);
  if ((msgsnd(msqid, (void *)&message, strlen(message.mtext) + 1, 0)) == -1) {
    perror("msgsnd:processB(MessageSend) ");
    exit(1);
  }
  printf("processB(MessageSend)   : end\n");
  return 0;
}


x86 assembly (clang, -O0):
<send_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe69(%rip),%rdi
mov    $0x4e,%esi
call   10b0 <ftok@plt>
mov    %eax,-0x88(%rbp)
mov    -0x88(%rbp),%edi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
call   1030 <msgget@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0xffffffff,-0x84(%rbp)
jne    1220 <send_msg+0x90>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
mov    0x2dd4(%rip),%rax
mov    (%rax),%edx
lea    0xe20(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x84(%rbp),%esi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movslq -0x4(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x80(%rbp),%rdi
add    $0x8,%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x80(%rbp),%rsi
add    $0x8,%rsi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x84(%rbp),%eax
mov    %eax,-0x9c(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x80(%rbp),%rdi
add    $0x8,%rdi
call   1050 <strlen@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
xor    %ecx,%ecx
call   1070 <msgsnd@plt>
cmp    $0xffffffff,%eax
jne    12c1 <send_msg+0x131>
lea    0xdec(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_msg>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xee8(%rip),%rdi
call   1050 <puts@plt>
lea    0xe40(%rip),%rdi
mov    $0x4e,%esi
call   10c0 <ftok@plt>
mov    0x2df7(%rip),%rcx
mov    $0x1b6,%esi
or     (%rcx),%esi
mov    %eax,%edi
call   1030 <msgget@plt>
cmp    $0xffffffff,%eax
je     1252 <send_msg+0xb2>
mov    %eax,%ebx
lea    0xe3e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
movslq %ebp,%rax
mov    %rax,(%rsp)
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xe3d(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rsp,%rsi
mov    %ebx,%edi
xor    %ecx,%ecx
call   1080 <msgsnd@plt>
cmp    $0xffffffff,%eax
je     127e <send_msg+0xde>
lea    0xe79(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
mov    0x2d76(%rip),%rax
mov    (%rax),%edx
lea    0xda2(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xdf9(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.msgbuff = type { i64, [100 x i8] }
%struct.msqid_ds = type { i32 }
@.str = [32 x i8] c"processB(MessageSend) : start\0A\00"
@.str.1 = [13 x i8] c"keyfilepath2\00"
@IPC_CREAT = global i32 0
@stderr = global i32 0
@.str.2 = [30 x i8] c"msgget failed with error: %d\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [38 x i8] c"processB(MessageSend) : msqID = %d\0A\00"
@.str.4 = [45 x i8] c"processB(MessageSend) : send message = %s\0A\00"
@.str.5 = [30 x i8] c"msgsnd:processB(MessageSend) \00"
@.str.6 = [31 x i8] c"processB(MessageSend) : end\0A\00"
define i32 @send_msg(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.msgbuff
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.msqid_ds
store i32 %0, i32* %3
store i8* %1, i8** %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @ftok(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 78)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = load i32, i32* @IPC_CREAT
%13 = or i32 438, %12
%14 = call i32 @msgget(i32 %11, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = load i32, i32* %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds %struct.msgbuff, %struct.msgbuff* %5, i32 0, i32 0
store i64 %27, i64* %28
%29 = getelementptr inbounds %struct.msgbuff, %struct.msgbuff* %5, i32 0, i32 1
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %29, i64 0, i64 0
%31 = load i8*, i8** %4
%32 = call i32 @strcpy(i8* %30, i8* %31)
%33 = getelementptr inbounds %struct.msgbuff, %struct.msgbuff* %5, i32 0, i32 1
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %33, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %34)
%36 = load i32, i32* %6
%37 = bitcast %struct.msgbuff* %5 to i8*
%38 = getelementptr inbounds %struct.msgbuff, %struct.msgbuff* %5, i32 0, i32 1
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %38, i64 0, i64 0
%40 = call i64 @strlen(i8* %39)
%41 = add nsw i64 %40, 1
%42 = call i32 @msgsnd(i32 %36, i8* %37, i64 %41, i32 0)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %23
%45 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %23
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.msgbuff = type { i64, [100 x i8] }
@.str.1 = [13 x i8] c"keyfilepath2\00"
@IPC_CREAT = global i32 0
@stderr = global i32 0
@.str.2 = [30 x i8] c"msgget failed with error: %d\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [38 x i8] c"processB(MessageSend) : msqID = %d\0A\00"
@.str.4 = [45 x i8] c"processB(MessageSend) : send message = %s\0A\00"
@.str.5 = [30 x i8] c"msgsnd:processB(MessageSend) \00"
@str = [31 x i8] c"processB(MessageSend) : start\00"
@str.7 = [30 x i8] c"processB(MessageSend) : end\00"
define i32 @send_msg(i32 %0, i8* %1) {
%3 = alloca %struct.msgbuff
%4 = bitcast %struct.msgbuff* %3 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @ftok(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 78)
%7 = load i32, i32* @IPC_CREAT
%8 = or i32 %7, 438
%9 = tail call i32 @msgget(i32 %6, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%19 = sext i32 %0 to i64
%20 = getelementptr inbounds %struct.msgbuff, %struct.msgbuff* %3, i64 0, i32 0
store i64 %19, i64* %20
%21 = getelementptr inbounds %struct.msgbuff, %struct.msgbuff* %3, i64 0, i32 1, i64 0
%22 = call i32 @strcpy(i8* %21, i8* %1)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %21)
%24 = call i64 @strlen(i8* %21)
%25 = add nsw i64 %24, 1
%26 = call i32 @msgsnd(i32 %9, i8* %4, i64 %25, i32 0)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %17
%29 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %17
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.7, i64 0, i64 0))
ret i32 0
}