#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_unsigned_int_from_mem(unsigned int, char **,
                                           struct target *);
int /*<<< orphan*/ free_dumped_params(char **, int);
void *malloc(int);
int dump_getcpu_cache(int depth, unsigned int addr, char **dumped_params,
                      struct target *target) {
  char **dumped_type_params;
  unsigned int arm_tracing_blob = addr;
  int len = 0;
  if (depth < 0) {
    *dumped_params = malloc(0);
    return len;
  }
  dumped_type_params = malloc(1 * (sizeof(char *)));
  if (depth >= 0) {
    len += dump_long_unsigned_int_from_mem(arm_tracing_blob,
                                           &dumped_type_params[0], target);
  }
  *dumped_params = copy_params(dumped_type_params, 1, &len);
  free_dumped_params(dumped_type_params, 1);
  return len;
}


x86 assembly (clang, -O0):
<dump_getcpu_cache>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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)
movl   $0x0,-0x30(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1189 <dump_getcpu_cache+0x49>
xor    %edi,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ee <dump_getcpu_cache+0xae>
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11be <dump_getcpu_cache+0x7e>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <dump_long_unsigned_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x30(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
lea    -0x30(%rbp),%rdx
call   1050 <copy_params@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
call   1040 <free_dumped_params@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_getcpu_cache>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
test   %edi,%edi
js     1199 <dump_getcpu_cache+0x59>
mov    %rcx,%r15
mov    %esi,%ebp
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %rax,%rsi
mov    %r15,%rdx
call   1030 <dump_long_unsigned_int_from_mem@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <copy_params@plt>
mov    %rax,(%r14)
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <free_dumped_params@plt>
mov    0x4(%rsp),%ebx
jmp    11a5 <dump_getcpu_cache+0x65>
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <malloc@plt>
mov    %rax,(%r14)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.target = type { i32 }
define i32 @dump_getcpu_cache(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
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8** %2, i8*** %8
store %struct.target* %3, %struct.target** %9
%13 = load i32, i32* %7
store i32 %13, i32* %11
store i32 0, i32* %12
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = call i8* @malloc(i32 0)
%18 = load i8**, i8*** %8
store i8* %17, i8** %18
%19 = load i32, i32* %12
store i32 %19, i32* %5
br label %42
20: ; preds = %4
%21 = call i8* @malloc(i32 8)
%22 = bitcast i8* %21 to i8**
store i8** %22, i8*** %10
%23 = load i32, i32* %6
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %35
25: ; preds = %20
%26 = load i32, i32* %11
%27 = load i8**, i8*** %10
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load %struct.target*, %struct.target** %9
%30 = call i64 @dump_long_unsigned_int_from_mem(i32 %26, i8** %28, %struct.target* %29)
%31 = load i32, i32* %12
%32 = sext i32 %31 to i64
%33 = add nsw i64 %32, %30
%34 = trunc i64 %33 to i32
store i32 %34, i32* %12
br label %35
35: ; preds = %25, %20
%36 = load i8**, i8*** %10
%37 = call i8* @copy_params(i8** %36, i32 1, i32* %12)
%38 = load i8**, i8*** %8
store i8* %37, i8** %38
%39 = load i8**, i8*** %10
%40 = call i32 @free_dumped_params(i8** %39, i32 1)
%41 = load i32, i32* %12
store i32 %41, i32* %5
br label %42
42: ; preds = %35, %16
%43 = load i32, i32* %5
ret i32 %43
}

LLVM IR (-O2):
%struct.target = type { i32 }
define i32 @dump_getcpu_cache(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 %18
10: ; preds = %4
%11 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%12 = bitcast i8* %11 to i8**
%13 = tail call i64 @dump_long_unsigned_int_from_mem(i32 %1, i8** %12, %struct.target* %3)
%14 = trunc i64 %13 to i32
store i32 %14, i32* %5
%15 = call i8* @copy_params(i8** %12, i32 1, i32* %5)
store i8* %15, i8** %2
%16 = call i32 @free_dumped_params(i8** %12, i32 1)
%17 = load i32, i32* %5
br label %18
18: ; preds = %10, %8
%19 = phi i32 [ %17, %10 ], [ 0, %8 ]
ret i32 %19
}