#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 target {
  int dummy;
};

/* Variables and functions */
char *copy_params(char **, int, int *);
scalar_t__ dump_long_int_from_mem(unsigned int, char **, struct target *);
int /*<<< orphan*/ free_dumped_params(char **, int);
void *malloc(int);
int dump_mq_attr(int depth, unsigned int addr, char **dumped_params,
                 struct target *target) {
  char **dumped_type_params;
  unsigned int arm_tracing_mq_flags = addr;
  unsigned int arm_tracing_mq_maxmsg = addr + 4;
  unsigned int arm_tracing_mq_msgsize = addr + 8;
  unsigned int arm_tracing_mq_curmsgs = addr + 12;
  unsigned int arm_tracing___reserved = addr + 16;
  int len = 0;
  if (depth < 0) {
    *dumped_params = malloc(0);
    return len;
  }
  dumped_type_params = malloc(5 * (sizeof(char *)));
  if (depth >= 0) {
    len += dump_long_int_from_mem(arm_tracing_mq_flags, &dumped_type_params[0],
                                  target);
    len += dump_long_int_from_mem(arm_tracing_mq_maxmsg, &dumped_type_params[1],
                                  target);
    len += dump_long_int_from_mem(arm_tracing_mq_msgsize,
                                  &dumped_type_params[2], target);
    len += dump_long_int_from_mem(arm_tracing_mq_curmsgs,
                                  &dumped_type_params[3], target);
    len += dump_long_int_from_mem(arm_tracing___reserved,
                                  &dumped_type_params[4], target);
  }
  *dumped_params = copy_params(dumped_type_params, 5, &len);
  free_dumped_params(dumped_type_params, 5);
  return len;
}


x86 assembly (clang, -O0):
<dump_mq_attr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%eax
add    $0xc,%eax
mov    %eax,-0x38(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11ad <dump_mq_attr+0x6d>
xor    %edi,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1296 <dump_mq_attr+0x156>
mov    $0x28,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1266 <dump_mq_attr+0x126>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <dump_long_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x40(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%rsi
add    $0x8,%rsi
mov    -0x20(%rbp),%rdx
call   1030 <dump_long_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x40(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x40(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x28(%rbp),%rsi
add    $0x10,%rsi
mov    -0x20(%rbp),%rdx
call   1030 <dump_long_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x40(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x28(%rbp),%rsi
add    $0x18,%rsi
mov    -0x20(%rbp),%rdx
call   1030 <dump_long_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x40(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x28(%rbp),%rsi
add    $0x20,%rsi
mov    -0x20(%rbp),%rdx
call   1030 <dump_long_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x40(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x5,%esi
lea    -0x40(%rbp),%rdx
call   1050 <copy_params@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
mov    $0x5,%esi
call   1040 <free_dumped_params@plt>
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_mq_attr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
test   %edi,%edi
js     1219 <dump_mq_attr+0xd9>
mov    %rcx,%r15
mov    %esi,%ebp
lea    0x10(%rbp),%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rbp),%eax
mov    %eax,0x8(%rsp)
lea    0x8(%rbp),%ebx
mov    %r14,0x10(%rsp)
lea    0x4(%rbp),%r14d
mov    $0x28,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %ebp,%edi
mov    %rax,%rsi
mov    %r15,%rdx
call   1030 <dump_long_int_from_mem@plt>
mov    %rax,%r13
lea    0x8(%r12),%rsi
mov    %r14d,%edi
mov    %r15,%rdx
call   1030 <dump_long_int_from_mem@plt>
mov    %rax,%rbp
add    %r13d,%ebp
lea    0x10(%r12),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
call   1030 <dump_long_int_from_mem@plt>
mov    %rax,%rbx
add    %ebp,%ebx
lea    0x18(%r12),%rsi
mov    0x8(%rsp),%edi
mov    %r15,%rdx
call   1030 <dump_long_int_from_mem@plt>
mov    %rax,%rbp
add    %ebx,%ebp
lea    0x20(%r12),%rsi
mov    0xc(%rsp),%edi
mov    %r15,%rdx
call   1030 <dump_long_int_from_mem@plt>
add    %ebp,%eax
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %r12,%rdi
mov    $0x5,%esi
call   1050 <copy_params@plt>
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx)
mov    %r12,%rdi
mov    $0x5,%esi
call   1040 <free_dumped_params@plt>
mov    0x4(%rsp),%ebx
jmp    1225 <dump_mq_attr+0xe5>
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <malloc@plt>
mov    %rax,(%r14)
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.target = type { i32 }
define i32 @dump_mq_attr(i32 %0, i32 %1, i8** %2, %struct.target* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8**
%9 = alloca %struct.target*
%10 = alloca i8**
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8** %2, i8*** %8
store %struct.target* %3, %struct.target** %9
%17 = load i32, i32* %7
store i32 %17, i32* %11
%18 = load i32, i32* %7
%19 = add i32 %18, 4
store i32 %19, i32* %12
%20 = load i32, i32* %7
%21 = add i32 %20, 8
store i32 %21, i32* %13
%22 = load i32, i32* %7
%23 = add i32 %22, 12
store i32 %23, i32* %14
%24 = load i32, i32* %7
%25 = add i32 %24, 16
store i32 %25, i32* %15
store i32 0, i32* %16
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %4
%29 = call i8* @malloc(i32 0)
%30 = load i8**, i8*** %8
store i8* %29, i8** %30
%31 = load i32, i32* %16
store i32 %31, i32* %5
br label %90
32: ; preds = %4
%33 = call i8* @malloc(i32 40)
%34 = bitcast i8* %33 to i8**
store i8** %34, i8*** %10
%35 = load i32, i32* %6
%36 = icmp sge i32 %35, 0
br i1 %36, label %37, label %83
37: ; preds = %32
%38 = load i32, i32* %11
%39 = load i8**, i8*** %10
%40 = getelementptr inbounds i8*, i8** %39, i64 0
%41 = load %struct.target*, %struct.target** %9
%42 = call i64 @dump_long_int_from_mem(i32 %38, i8** %40, %struct.target* %41)
%43 = load i32, i32* %16
%44 = sext i32 %43 to i64
%45 = add nsw i64 %44, %42
%46 = trunc i64 %45 to i32
store i32 %46, i32* %16
%47 = load i32, i32* %12
%48 = load i8**, i8*** %10
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load %struct.target*, %struct.target** %9
%51 = call i64 @dump_long_int_from_mem(i32 %47, i8** %49, %struct.target* %50)
%52 = load i32, i32* %16
%53 = sext i32 %52 to i64
%54 = add nsw i64 %53, %51
%55 = trunc i64 %54 to i32
store i32 %55, i32* %16
%56 = load i32, i32* %13
%57 = load i8**, i8*** %10
%58 = getelementptr inbounds i8*, i8** %57, i64 2
%59 = load %struct.target*, %struct.target** %9
%60 = call i64 @dump_long_int_from_mem(i32 %56, i8** %58, %struct.target* %59)
%61 = load i32, i32* %16
%62 = sext i32 %61 to i64
%63 = add nsw i64 %62, %60
%64 = trunc i64 %63 to i32
store i32 %64, i32* %16
%65 = load i32, i32* %14
%66 = load i8**, i8*** %10
%67 = getelementptr inbounds i8*, i8** %66, i64 3
%68 = load %struct.target*, %struct.target** %9
%69 = call i64 @dump_long_int_from_mem(i32 %65, i8** %67, %struct.target* %68)
%70 = load i32, i32* %16
%71 = sext i32 %70 to i64
%72 = add nsw i64 %71, %69
%73 = trunc i64 %72 to i32
store i32 %73, i32* %16
%74 = load i32, i32* %15
%75 = load i8**, i8*** %10
%76 = getelementptr inbounds i8*, i8** %75, i64 4
%77 = load %struct.target*, %struct.target** %9
%78 = call i64 @dump_long_int_from_mem(i32 %74, i8** %76, %struct.target* %77)
%79 = load i32, i32* %16
%80 = sext i32 %79 to i64
%81 = add nsw i64 %80, %78
%82 = trunc i64 %81 to i32
store i32 %82, i32* %16
br label %83
83: ; preds = %37, %32
%84 = load i8**, i8*** %10
%85 = call i8* @copy_params(i8** %84, i32 5, i32* %16)
%86 = load i8**, i8*** %8
store i8* %85, i8** %86
%87 = load i8**, i8*** %10
%88 = call i32 @free_dumped_params(i8** %87, i32 5)
%89 = load i32, i32* %16
store i32 %89, i32* %5
br label %90
90: ; preds = %83, %28
%91 = load i32, i32* %5
ret i32 %91
}

LLVM IR (-O2):
%struct.target = type { i32 }
define i32 @dump_mq_attr(i32 %0, i32 %1, i8** nocapture writeonly %2, %struct.target* %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = icmp slt i32 %0, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i8* @malloc(i32 0)
store i8* %9, i8** %2
br label %38
10: ; preds = %4
%11 = add i32 %1, 16
%12 = add i32 %1, 12
%13 = add i32 %1, 8
%14 = add i32 %1, 4
%15 = tail call dereferenceable_or_null(40) i8* @malloc(i32 40)
%16 = bitcast i8* %15 to i8**
%17 = tail call i64 @dump_long_int_from_mem(i32 %1, i8** %16, %struct.target* %3)
%18 = trunc i64 %17 to i32
%19 = getelementptr inbounds i8*, i8** %16, i64 1
%20 = tail call i64 @dump_long_int_from_mem(i32 %14, i8** %19, %struct.target* %3)
%21 = trunc i64 %20 to i32
%22 = add i32 %18, %21
%23 = getelementptr inbounds i8*, i8** %16, i64 2
%24 = tail call i64 @dump_long_int_from_mem(i32 %13, i8** %23, %struct.target* %3)
%25 = trunc i64 %24 to i32
%26 = add i32 %22, %25
%27 = getelementptr inbounds i8*, i8** %16, i64 3
%28 = tail call i64 @dump_long_int_from_mem(i32 %12, i8** %27, %struct.target* %3)
%29 = trunc i64 %28 to i32
%30 = add i32 %26, %29
%31 = getelementptr inbounds i8*, i8** %16, i64 4
%32 = tail call i64 @dump_long_int_from_mem(i32 %11, i8** %31, %struct.target* %3)
%33 = trunc i64 %32 to i32
%34 = add i32 %30, %33
store i32 %34, i32* %5
%35 = call i8* @copy_params(i8** %16, i32 5, i32* %5)
store i8* %35, i8** %2
%36 = call i32 @free_dumped_params(i8** %16, i32 5)
%37 = load i32, i32* %5
br label %38
38: ; preds = %10, %8
%39 = phi i32 [ %37, %10 ], [ 0, %8 ]
ret i32 %39
}