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

/* Variables and functions */
int /*<<< orphan*/ IPC_CREAT;
int /*<<< orphan*/ memset(char *, int, int);
int msgget(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ publish(int, char *);
int /*<<< orphan*/ scanf(char *, char *);
int main(int argc, char **argv) {
  char buf[(128)];
  int msgid = -1;
  msgid = msgget((key_t)1111, (IPC_CREAT));
  if (msgid < 0) {
    perror("failed when create msg");
    return -1;
  }
  while (1) {
    memset(buf, 0x00, sizeof(buf));
    scanf("%s", buf);
    publish(msgid, buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x94(%rbp)
ff ff ff
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
mov    $0x457,%edi
call   1030 <msgget@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
jge    11b3 <main+0x63>
lea    0xe60(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
add    $0xa0,%rsp
pop    %rbp
ret
jmp    11b8 <main+0x68>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
lea    -0x90(%rbp),%rsi
lea    0xe3e(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x94(%rbp),%edi
lea    -0x90(%rbp),%rsi
call   1070 <publish@plt>
jmp    11b8 <main+0x68>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
mov    $0x457,%edi
call   1030 <msgget@plt>
test   %eax,%eax
js     11a6 <main+0x56>
mov    %eax,%ebp
mov    %rsp,%rbx
lea    0xe99(%rip),%r14
xchg   %ax,%ax
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <publish@plt>
jmp    1180 <main+0x30>
lea    0xe53(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@IPC_CREAT = global i32 0
@.str = [23 x i8] c"failed when create msg\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [128 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %7
%8 = load i32, i32* @IPC_CREAT
%9 = call i32 @msgget(i32 1111, i32 %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
ret i32 -1
14: ; preds = %2
br label %15
15: ; preds = %14, %15
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%17 = call i32 @memset(i8* %16, i32 0, i32 128)
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %7
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%22 = call i32 @publish(i32 %20, i8* %21)
br label %15
}

LLVM IR (-O2):
@IPC_CREAT = global i32 0
@.str = [23 x i8] c"failed when create msg\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @IPC_CREAT
%6 = tail call i32 @msgget(i32 1111, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
ret i32 -1
10: ; preds = %2, %10
%11 = call i32 @memset(i8* %4, i32 0, i32 128)
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%13 = call i32 @publish(i32 %6, i8* %4)
br label %10
}