#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_unsigned_int_from_mem(unsigned int, char **, struct target *);
int /*<<< orphan*/ free_dumped_params(char **, int);
void *malloc(int);
int dump___user_cap_data_struct(int depth, unsigned int addr,
                                char **dumped_params, struct target *target) {
  char **dumped_type_params;
  unsigned int arm_tracing_effective = addr;
  unsigned int arm_tracing_permitted = addr + 4;
  unsigned int arm_tracing_inheritable = addr + 8;
  int len = 0;
  if (depth < 0) {
    *dumped_params = malloc(0);
    return len;
  }
  dumped_type_params = malloc(3 * (sizeof(char *)));
  if (depth >= 0) {
    len += dump_unsigned_int_from_mem(arm_tracing_effective,
                                      &dumped_type_params[0], target);
    len += dump_unsigned_int_from_mem(arm_tracing_permitted,
                                      &dumped_type_params[1], target);
    len += dump_unsigned_int_from_mem(arm_tracing_inheritable,
                                      &dumped_type_params[2], target);
  }
  *dumped_params = copy_params(dumped_type_params, 3, &len);
  free_dumped_params(dumped_type_params, 3);
  return len;
}


x86 assembly (clang, -O0):
<dump___user_cap_data_struct>:
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)
movl   $0x0,-0x38(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    119b <dump___user_cap_data_struct+0x5b>
xor    %edi,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1242 <dump___user_cap_data_struct+0x102>
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1212 <dump___user_cap_data_struct+0xd2>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <dump_unsigned_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x38(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%rsi
add    $0x8,%rsi
mov    -0x20(%rbp),%rdx
call   1060 <dump_unsigned_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x38(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x28(%rbp),%rsi
add    $0x10,%rsi
mov    -0x20(%rbp),%rdx
call   1060 <dump_unsigned_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x38(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x3,%esi
lea    -0x38(%rbp),%rdx
call   1040 <copy_params@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
mov    $0x3,%esi
call   1030 <free_dumped_params@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump___user_cap_data_struct>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
test   %edi,%edi
js     11cd <dump___user_cap_data_struct+0x8d>
mov    %rcx,%r15
mov    %esi,%ebx
lea    0x8(%rbx),%r13d
lea    0x4(%rbx),%ebp
mov    $0x18,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %ebx,%edi
mov    %rax,%rsi
mov    %r15,%rdx
call   1060 <dump_unsigned_int_from_mem@plt>
mov    %rax,%rbx
lea    0x8(%r12),%rsi
mov    %ebp,%edi
mov    %r15,%rdx
call   1060 <dump_unsigned_int_from_mem@plt>
mov    %rax,%rbp
add    %ebx,%ebp
lea    0x10(%r12),%rsi
mov    %r13d,%edi
mov    %r15,%rdx
call   1060 <dump_unsigned_int_from_mem@plt>
add    %ebp,%eax
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %r12,%rdi
mov    $0x3,%esi
call   1040 <copy_params@plt>
mov    %rax,(%r14)
mov    %r12,%rdi
mov    $0x3,%esi
call   1030 <free_dumped_params@plt>
mov    0x4(%rsp),%ebx
jmp    11d9 <dump___user_cap_data_struct+0x99>
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <malloc@plt>
mov    %rax,(%r14)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.target = type { i32 }
define i32 @dump___user_cap_data_struct(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
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8** %2, i8*** %8
store %struct.target* %3, %struct.target** %9
%15 = load i32, i32* %7
store i32 %15, i32* %11
%16 = load i32, i32* %7
%17 = add i32 %16, 4
store i32 %17, i32* %12
%18 = load i32, i32* %7
%19 = add i32 %18, 8
store i32 %19, i32* %13
store i32 0, i32* %14
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %4
%23 = call i8* @malloc(i32 0)
%24 = load i8**, i8*** %8
store i8* %23, i8** %24
%25 = load i32, i32* %14
store i32 %25, i32* %5
br label %66
26: ; preds = %4
%27 = call i8* @malloc(i32 24)
%28 = bitcast i8* %27 to i8**
store i8** %28, i8*** %10
%29 = load i32, i32* %6
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %59
31: ; preds = %26
%32 = load i32, i32* %11
%33 = load i8**, i8*** %10
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load %struct.target*, %struct.target** %9
%36 = call i64 @dump_unsigned_int_from_mem(i32 %32, i8** %34, %struct.target* %35)
%37 = load i32, i32* %14
%38 = sext i32 %37 to i64
%39 = add nsw i64 %38, %36
%40 = trunc i64 %39 to i32
store i32 %40, i32* %14
%41 = load i32, i32* %12
%42 = load i8**, i8*** %10
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load %struct.target*, %struct.target** %9
%45 = call i64 @dump_unsigned_int_from_mem(i32 %41, i8** %43, %struct.target* %44)
%46 = load i32, i32* %14
%47 = sext i32 %46 to i64
%48 = add nsw i64 %47, %45
%49 = trunc i64 %48 to i32
store i32 %49, i32* %14
%50 = load i32, i32* %13
%51 = load i8**, i8*** %10
%52 = getelementptr inbounds i8*, i8** %51, i64 2
%53 = load %struct.target*, %struct.target** %9
%54 = call i64 @dump_unsigned_int_from_mem(i32 %50, i8** %52, %struct.target* %53)
%55 = load i32, i32* %14
%56 = sext i32 %55 to i64
%57 = add nsw i64 %56, %54
%58 = trunc i64 %57 to i32
store i32 %58, i32* %14
br label %59
59: ; preds = %31, %26
%60 = load i8**, i8*** %10
%61 = call i8* @copy_params(i8** %60, i32 3, i32* %14)
%62 = load i8**, i8*** %8
store i8* %61, i8** %62
%63 = load i8**, i8*** %10
%64 = call i32 @free_dumped_params(i8** %63, i32 3)
%65 = load i32, i32* %14
store i32 %65, i32* %5
br label %66
66: ; preds = %59, %22
%67 = load i32, i32* %5
ret i32 %67
}

LLVM IR (-O2):
%struct.target = type { i32 }
define i32 @dump___user_cap_data_struct(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 %28
10: ; preds = %4
%11 = add i32 %1, 8
%12 = add i32 %1, 4
%13 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%14 = bitcast i8* %13 to i8**
%15 = tail call i64 @dump_unsigned_int_from_mem(i32 %1, i8** %14, %struct.target* %3)
%16 = trunc i64 %15 to i32
%17 = getelementptr inbounds i8*, i8** %14, i64 1
%18 = tail call i64 @dump_unsigned_int_from_mem(i32 %12, i8** %17, %struct.target* %3)
%19 = trunc i64 %18 to i32
%20 = add i32 %16, %19
%21 = getelementptr inbounds i8*, i8** %14, i64 2
%22 = tail call i64 @dump_unsigned_int_from_mem(i32 %11, i8** %21, %struct.target* %3)
%23 = trunc i64 %22 to i32
%24 = add i32 %20, %23
store i32 %24, i32* %5
%25 = call i8* @copy_params(i8** %14, i32 3, i32* %5)
store i8* %25, i8** %2
%26 = call i32 @free_dumped_params(i8** %14, i32 3)
%27 = load i32, i32* %5
br label %28
28: ; preds = %10, %8
%29 = phi i32 [ %27, %10 ], [ 0, %8 ]
ret i32 %29
}