#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*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ mq_open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ mq_send(scalar_t__, char *, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mq_unlink(char *);
int /*<<< orphan*/ printLog(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ strlen(char *);
void cleanupDomo() {
  mqd_t mq = mq_open("/domo_request_queue", O_WRONLY);
  if ((mqd_t)-1 == mq) {
    printLog("Domo daemon is not running.\n");
  } else {
    char cmd[16];
    memset(cmd, 0, sizeof cmd);
    sprintf(cmd, "%d", 0);
    mq_send(mq, cmd, strlen(cmd), 0);
    int clientId;
    char queueName[strlen("/domo_response_queue_") + 4];
    for (clientId = 1; clientId < 256; clientId++) {
      sprintf(queueName, "%s%d", "/domo_response_queue_", clientId);
      mq_unlink(queueName);
    }
  }
}


x86 assembly (clang, -O0):
<cleanupDomo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1060 <mq_open@plt>
mov    %rax,-0x8(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    -0x8(%rbp),%rax
jne    11b3 <cleanupDomo+0x43>
lea    0xe6b(%rip),%rdi
call   1070 <printLog@plt>
jmp    1282 <cleanupDomo+0x112>
lea    -0x20(%rbp),%rdi
mov    %rdi,-0x50(%rbp)
xor    %esi,%esi
mov    %esi,-0x44(%rbp)
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%eax
lea    0xe71(%rip),%rsi
mov    %eax,%edx
call   1080 <sprintf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
call   1030 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x44(%rbp),%ecx
mov    %eax,%edx
call   1050 <mq_send@plt>
lea    0xe28(%rip),%rdi
call   1030 <strlen@plt>
add    $0x4,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x100,-0x24(%rbp)
jge    127b <cleanupDomo+0x10b>
mov    -0x40(%rbp),%rdi
mov    -0x24(%rbp),%ecx
lea    0xdf1(%rip),%rsi
lea    0xdd4(%rip),%rdx
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    -0x40(%rbp),%rdi
call   1090 <mq_unlink@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    123b <cleanupDomo+0xcb>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cleanupDomo>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdi
call   1060 <mq_open@plt>
cmp    $0xffffffffffffffff,%rax
je     1257 <cleanupDomo+0xe7>
mov    %rax,%rbx
lea    -0x40(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    0xe8c(%rip),%rsi
mov    %r14,%rdi
xor    %edx,%edx
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <mq_send@plt>
lea    0xe4a(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rsp,%r13
add    $0x4,%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    $0x1,%ebx
lea    0xe35(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %r15,%rdi
call   1090 <mq_unlink@plt>
add    $0x1,%ebx
cmp    $0x100,%ebx
jne    1220 <cleanupDomo+0xb0>
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb6(%rip),%rdi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <printLog@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"/domo_request_queue\00"
@O_WRONLY = global i32 0
@.str.1 = [29 x i8] c"Domo daemon is not running.\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [22 x i8] c"/domo_response_queue_\00"
@.str.4 = [5 x i8] c"%s%d\00"
define void @cleanupDomo() {
%1 = alloca i64
%2 = alloca [16 x i8]
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = load i32, i32* @O_WRONLY
%7 = call i64 @mq_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %6)
store i64 %7, i64* %1
%8 = load i64, i64* %1
%9 = icmp eq i64 -1, %8
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @printLog(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %39
12: ; preds = %0
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 16)
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%16 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* null)
%17 = load i64, i64* %1
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @mq_send(i64 %17, i8* %18, i32 %20, i32 0)
%22 = call i32 @strlen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%23 = add nsw i32 %22, 4
%24 = zext i32 %23 to i64
%25 = call i8* @llvm.stacksave()
store i8* %25, i8** %4
%26 = alloca i8, i64 %24
store i64 %24, i64* %5
store i32 1, i32* %3
br label %27
27: ; preds = %34, %12
%28 = load i32, i32* %3
%29 = icmp slt i32 %28, 256
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load i32, i32* %3
%32 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = call i32 @mq_unlink(i8* %26)
br label %34
34: ; preds = %30
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %27
37: ; preds = %27
%38 = load i8*, i8** %4
br label %39
39: ; preds = %37, %10
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"/domo_request_queue\00"
@O_WRONLY = global i32 0
@.str.1 = [29 x i8] c"Domo daemon is not running.\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [22 x i8] c"/domo_response_queue_\00"
@.str.4 = [5 x i8] c"%s%d\00"
define void @cleanupDomo() {
%1 = alloca [16 x i8]
%2 = load i32, i32* @O_WRONLY
%3 = tail call i64 @mq_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i64 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @printLog(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %25
7: ; preds = %0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 16)
%10 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* null)
%11 = call i32 @strlen(i8* %8)
%12 = call i32 @mq_send(i64 %3, i8* %8, i32 %11, i32 0)
%13 = call i32 @strlen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%14 = add nsw i32 %13, 4
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
%17 = alloca i8, i64 %15
br label %18
18: ; preds = %7, %18
%19 = phi i32 [ 1, %7 ], [ %22, %18 ]
%20 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = call i32 @mq_unlink(i8* %17)
%22 = add nuw nsw i32 %19, 1
%23 = icmp eq i32 %22, 256
br i1 %23, label %24, label %18
24: ; preds = %18
br label %25
25: ; preds = %24, %5
ret void
}