#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_long_unsigned_int_from_mem(unsigned int, char **,
                                                struct target *);
int /*<<< orphan*/ free_dumped_params(char **, int);
void *malloc(int);
int dump_rlimit64(int depth, unsigned int addr, char **dumped_params,
                  struct target *target) {
  char **dumped_type_params;
  unsigned int arm_tracing_rlim_cur = addr;
  unsigned int arm_tracing_rlim_max = addr + 8;
  int len = 0;
  if (depth < 0) {
    *dumped_params = malloc(0);
    return len;
  }
  dumped_type_params = malloc(2 * (sizeof(char *)));
  if (depth >= 0) {
    len += dump_long_long_unsigned_int_from_mem(arm_tracing_rlim_cur,
                                                &dumped_type_params[0], target);
    len += dump_long_long_unsigned_int_from_mem(arm_tracing_rlim_max,
                                                &dumped_type_params[1], target);
  }
  *dumped_params = copy_params(dumped_type_params, 2, &len);
  free_dumped_params(dumped_type_params, 2);
  return len;
}


x86 assembly (clang, -O0):
<dump_rlimit64>:
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    $0x8,%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1192 <dump_rlimit64+0x52>
xor    %edi,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1218 <dump_rlimit64+0xd8>
mov    $0x10,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11e8 <dump_rlimit64+0xa8>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <dump_long_long_unsigned_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x34(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%rsi
add    $0x8,%rsi
mov    -0x20(%rbp),%rdx
call   1030 <dump_long_long_unsigned_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x34(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x2,%esi
lea    -0x34(%rbp),%rdx
call   1050 <copy_params@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
mov    $0x2,%esi
call   1040 <free_dumped_params@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_rlimit64>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
test   %edi,%edi
js     11b5 <dump_rlimit64+0x75>
mov    %rcx,%r15
mov    %esi,%ebx
lea    0x8(%rbx),%ebp
mov    $0x10,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %ebx,%edi
mov    %rax,%rsi
mov    %r15,%rdx
call   1030 <dump_long_long_unsigned_int_from_mem@plt>
mov    %rax,%rbx
lea    0x8(%r12),%rsi
mov    %ebp,%edi
mov    %r15,%rdx
call   1030 <dump_long_long_unsigned_int_from_mem@plt>
add    %ebx,%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    %r12,%rdi
mov    $0x2,%esi
call   1050 <copy_params@plt>
mov    %rax,(%r14)
mov    %r12,%rdi
mov    $0x2,%esi
call   1040 <free_dumped_params@plt>
mov    0xc(%rsp),%ebx
jmp    11c1 <dump_rlimit64+0x81>
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <malloc@plt>
mov    %rax,(%r14)
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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