#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 mq_attr {
  int mq_maxmsg;
  int mq_msgsize;
  int mq_curmsgs;
};
typedef scalar_t__ mqd_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int /*<<< orphan*/ mq_close(scalar_t__);
int mq_getattr(scalar_t__, struct mq_attr *);
scalar_t__ mq_open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(void) {
  mqd_t mqd;
  mqd = mq_open("/abc", O_RDWR);
  if (mqd == (mqd_t)-1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day0c/mq_getattr.c",
              22, "mq_open", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  struct mq_attr attr;
  if (mq_getattr(mqd, &attr) == -1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day0c/mq_getattr.c",
              26, "mq_getattr", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  printf("mq_maxmsg=%d, mq_msgsize=%d, mq_curmsgs=%d\n", attr.mq_maxmsg,
         attr.mq_msgsize, attr.mq_curmsgs);
  mq_close(mqd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1060 <mq_open@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0xffffffffffffffff,-0x10(%rbp)
jne    11f5 <main+0x85>
jmp    11a8 <main+0x38>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%r9
lea    0xe36(%rip),%rsi
lea    0xe3f(%rip),%rdx
mov    $0x16,%ecx
lea    0xecc(%rip),%r8
call   1050 <fprintf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <mq_getattr@plt>
cmp    $0xffffffff,%eax
jne    125d <main+0xed>
jmp    1210 <main+0xa0>
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%r9
lea    0xdce(%rip),%rsi
lea    0xdd7(%rip),%rdx
mov    $0x1a,%ecx
lea    0xe6c(%rip),%r8
call   1050 <fprintf@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <mq_close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    0xe7b(%rip),%rdi
call   1060 <mq_open@plt>
cmp    $0xffffffffffffffff,%rax
je     11ca <main+0x5a>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1090 <mq_getattr@plt>
cmp    $0xffffffff,%eax
je     11ff <main+0x8f>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
mov    0x8(%rsp),%ecx
lea    0xf0c(%rip),%rdi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <mq_close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e07(%rip),%rax
mov    (%rax),%ebx
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe1d(%rip),%rsi
lea    0xe26(%rip),%rdx
lea    0xeb8(%rip),%r8
mov    %ebx,%edi
mov    $0x16,%ecx
jmp    1232 <main+0xc2>
mov    0x2dd2(%rip),%rax
mov    (%rax),%ebx
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xde8(%rip),%rsi
lea    0xdf1(%rip),%rdx
lea    0xe8b(%rip),%r8
mov    %ebx,%edi
mov    $0x1a,%ecx
mov    %rax,%r9
call   1050 <fprintf@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.mq_attr = type { i32, i32, i32 }
@.str = [5 x i8] c"/abc\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.2 = [153 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day0c/mq_getattr.c\00"
@.str.3 = [8 x i8] c"mq_open\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.4 = [11 x i8] c"mq_getattr\00"
@.str.5 = [44 x i8] c"mq_maxmsg=%d, mq_msgsize=%d, mq_curmsgs=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca %struct.mq_attr
store i32 0, i32* %1
%4 = load i32, i32* @O_RDWR
%5 = call i64 @mq_open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %4)
store i64 %5, i64* %2
%6 = load i64, i64* %2
%7 = icmp eq i64 %6, -1
br i1 %7, label %8, label %17
8: ; preds = %0
br label %9
9: ; preds = %8
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.2, i64 0, i64 0), i32 22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; No predecessors!
br label %17
17: ; preds = %16, %0
%18 = load i64, i64* %2
%19 = call i32 @mq_getattr(i64 %18, %struct.mq_attr* %3)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %30
21: ; preds = %17
br label %22
22: ; preds = %21
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.2, i64 0, i64 0), i32 26, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; No predecessors!
br label %30
30: ; preds = %29, %17
%31 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i32 0, i32 0
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i32 0, i32 1
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %3, i32 0, i32 2
%36 = load i32, i32* %35
%37 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i32 %32, i32 %34, i32 %36)
%38 = load i64, i64* %2
%39 = call i32 @mq_close(i64 %38)
ret i32 0
}

LLVM IR (-O2):
%struct.mq_attr = type { i32, i32, i32 }
@.str = [5 x i8] c"/abc\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.2 = [153 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day0c/mq_getattr.c\00"
@.str.3 = [8 x i8] c"mq_open\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.4 = [11 x i8] c"mq_getattr\00"
@.str.5 = [44 x i8] c"mq_maxmsg=%d, mq_msgsize=%d, mq_curmsgs=%d\0A\00"
define i32 @main() {
%1 = alloca %struct.mq_attr
%2 = load i32, i32* @O_RDWR
%3 = tail call i64 @mq_open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i64 %3, -1
br i1 %4, label %5, label %12
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.2, i64 0, i64 0), i32 22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = bitcast %struct.mq_attr* %1 to i8*
%14 = call i32 @mq_getattr(i64 %3, %struct.mq_attr* %1)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.2, i64 0, i64 0), i32 26, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %12
%24 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %1, i64 0, i32 0
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %1, i64 0, i32 1
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.mq_attr, %struct.mq_attr* %1, i64 0, i32 2
%29 = load i32, i32* %28
%30 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i32 %25, i32 %27, i32 %29)
%31 = call i32 @mq_close(i64 %3)
ret i32 0
}