#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 scalar_t__ mqd_t;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ logg(scalar_t__, char *, int, char, char, char, char);
scalar_t__ mq_open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
void benchmark(int rounds) {
  int i = 0;
  char *dummy = "message\0";
  const char *MQ_NAME = "/mq-comlog01";
  mqd_t mqdes;
  mqdes = mq_open(MQ_NAME, O_WRONLY);
  if (mqdes < 0) {
    perror("mq_open");
    exit(1);
  }
  while (i < rounds) {
    logg(mqdes, dummy, 4, (char)65, (char)65, (char)66, (char)89);
    i++;
  }
  return;
}


x86 assembly (clang, -O0):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xea7(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xea5(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
call   1030 <mq_open@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    119f <benchmark+0x5f>
lea    0xe86(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    11a4 <benchmark+0x64>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e6 <benchmark+0xa6>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
mov    $0x41,%r8d
mov    $0x42,%r9d
mov    %r8d,%ecx
movl   $0x59,(%rsp)
call   1040 <logg@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a4 <benchmark+0x64>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
lea    0xeae(%rip),%rdi
call   1030 <mq_open@plt>
test   %rax,%rax
js     11b7 <benchmark+0x77>
test   %ebx,%ebx
jle    11ad <benchmark+0x6d>
mov    %rax,%r14
lea    0xe8d(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movl   $0x59,(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
mov    $0x41,%ecx
mov    $0x41,%r8d
mov    $0x42,%r9d
call   1040 <logg@plt>
add    $0xffffffff,%ebx
jne    1180 <benchmark+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe58(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"message\00\00"
@.str.1 = [13 x i8] c"/mq-comlog01\00"
@O_WRONLY = global i32 0
@.str.2 = [8 x i8] c"mq_open\00"
define void @benchmark(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i32 %0, i32* %2
store i32 0, i32* %3
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8** %5
%7 = load i8*, i8** %5
%8 = load i32, i32* @O_WRONLY
%9 = call i64 @mq_open(i8* %7, i32 %8)
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
br label %16
16: ; preds = %20, %15
%17 = load i32, i32* %3
%18 = load i32, i32* %2
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = load i64, i64* %6
%22 = load i8*, i8** %4
%23 = call i32 @logg(i64 %21, i8* %22, i32 4, i8 signext 65, i8 signext 65, i8 signext 66, i8 signext 89)
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %16
26: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"message\00\00"
@.str.1 = [13 x i8] c"/mq-comlog01\00"
@O_WRONLY = global i32 0
@.str.2 = [8 x i8] c"mq_open\00"
define void @benchmark(i32 %0) {
%2 = load i32, i32* @O_WRONLY
%3 = tail call i64 @mq_open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%4 = icmp slt i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = icmp sgt i32 %0, 0
br i1 %6, label %10, label %15
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %5, %10
%11 = phi i32 [ %13, %10 ], [ 0, %5 ]
%12 = tail call i32 @logg(i64 %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 4, i8 signext 65, i8 signext 65, i8 signext 66, i8 signext 89)
%13 = add nuw nsw i32 %11, 1
%14 = icmp eq i32 %13, %0
br i1 %14, label %15, label %10
15: ; preds = %10, %5
ret void
}