#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 *);
scalar_t__ dump_ptr(unsigned int, char **);
scalar_t__ dump_robust_list(int, unsigned int, char **, struct target *);
int /*<<< orphan*/ free_dumped_params(char **, int);
void *malloc(int);
unsigned int read_ptr_from_mem(unsigned int, struct target *);
int dump_robust_list_head(int depth, unsigned int addr, char **dumped_params,
                          struct target *target) {
  char **dumped_type_params;
  unsigned int anonymous_inner_struct_20 = addr;
  unsigned int arm_tracing_futex_offset = addr + 4;
  unsigned int arm_tracing_list_op_pending = addr + 8;
  int len = 0;
  if (depth < 0) {
    *dumped_params = malloc(0);
    return len;
  }
  dumped_type_params = malloc(3 * (sizeof(char *)));
  arm_tracing_list_op_pending =
      read_ptr_from_mem(arm_tracing_list_op_pending, target);
  if (depth == 0) {
    len += dump_robust_list(depth, anonymous_inner_struct_20,
                            &dumped_type_params[0], target);
    len += dump_long_int_from_mem(arm_tracing_futex_offset,
                                  &dumped_type_params[1], target);
    len += dump_ptr(arm_tracing_list_op_pending, &dumped_type_params[2]);
    *dumped_params = copy_params(dumped_type_params, 3, &len);
    free_dumped_params(dumped_type_params, 3);
    return len;
  }
  if (depth >= 1) {
    len += dump_robust_list(depth, anonymous_inner_struct_20,
                            &dumped_type_params[0], target);
    len += dump_long_int_from_mem(arm_tracing_futex_offset,
                                  &dumped_type_params[1], target);
    len += dump_robust_list(depth - 1, arm_tracing_list_op_pending,
                            &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_robust_list_head>:
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    11cb <dump_robust_list_head+0x5b>
xor    %edi,%edi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1327 <dump_robust_list_head+0x1b7>
mov    $0x18,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <read_ptr_from_mem@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1285 <dump_robust_list_head+0x115>
mov    -0x8(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1080 <dump_robust_list@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   1030 <dump_long_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
call   1050 <dump_ptr@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   1060 <copy_params@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
mov    $0x3,%esi
call   1040 <free_dumped_params@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1327 <dump_robust_list_head+0x1b7>
cmpl   $0x1,-0x8(%rbp)
jl     12f7 <dump_robust_list_head+0x187>
mov    -0x8(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1080 <dump_robust_list@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   1030 <dump_long_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x38(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x34(%rbp),%esi
mov    -0x28(%rbp),%rdx
add    $0x10,%rdx
mov    -0x20(%rbp),%rcx
call   1080 <dump_robust_list@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   1060 <copy_params@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
mov    $0x3,%esi
call   1040 <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_robust_list_head>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
movl   $0x0,0xc(%rsp)
test   %edi,%edi
js     1201 <dump_robust_list_head+0x91>
mov    %rcx,%r12
mov    %esi,%r14d
mov    %edi,%ebp
mov    %rbx,0x10(%rsp)
lea    0x4(%r14),%r13d
lea    0x8(%r14),%ebx
mov    $0x18,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    %ebx,%edi
mov    %r12,%rsi
call   1070 <read_ptr_from_mem@plt>
mov    %eax,%ebx
test   %ebp,%ebp
je     120d <dump_robust_list_head+0x9d>
mov    %ebp,%edi
mov    %r14d,%esi
mov    %r15,%rdx
mov    %r12,%rcx
call   1080 <dump_robust_list@plt>
mov    %rax,%r14
lea    0x8(%r15),%rsi
mov    %r13d,%edi
mov    %r12,%rdx
call   1030 <dump_long_int_from_mem@plt>
mov    %ebx,%esi
mov    %rax,%rbx
add    %r14d,%ebx
add    $0xffffffff,%ebp
mov    %r15,%rdx
add    $0x10,%rdx
mov    %ebp,%edi
mov    %r12,%rcx
call   1080 <dump_robust_list@plt>
add    %ebx,%eax
jmp    1245 <dump_robust_list_head+0xd5>
xor    %edi,%edi
call   1090 <malloc@plt>
mov    %rax,(%rbx)
jmp    1270 <dump_robust_list_head+0x100>
xor    %edi,%edi
mov    %r14d,%esi
mov    %r15,%rdx
mov    %r12,%rcx
call   1080 <dump_robust_list@plt>
mov    %rax,%r14
lea    0x8(%r15),%rsi
mov    %r13d,%edi
mov    %r12,%rdx
call   1030 <dump_long_int_from_mem@plt>
mov    %rax,%rbp
add    %r14d,%ebp
mov    %r15,%rsi
add    $0x10,%rsi
mov    %ebx,%edi
call   1050 <dump_ptr@plt>
add    %ebp,%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    %r15,%rdi
mov    $0x3,%esi
call   1060 <copy_params@plt>
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx)
mov    %r15,%rdi
mov    $0x3,%esi
call   1040 <free_dumped_params@plt>
mov    0xc(%rsp),%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_robust_list_head(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 %109
26: ; preds = %4
%27 = call i8* @malloc(i32 24)
%28 = bitcast i8* %27 to i8**
store i8** %28, i8*** %10
%29 = load i32, i32* %13
%30 = load %struct.target*, %struct.target** %9
%31 = call i32 @read_ptr_from_mem(i32 %29, %struct.target* %30)
store i32 %31, i32* %13
%32 = load i32, i32* %6
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %68
34: ; preds = %26
%35 = load i32, i32* %6
%36 = load i32, i32* %11
%37 = load i8**, i8*** %10
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load %struct.target*, %struct.target** %9
%40 = call i64 @dump_robust_list(i32 %35, i32 %36, i8** %38, %struct.target* %39)
%41 = load i32, i32* %14
%42 = sext i32 %41 to i64
%43 = add nsw i64 %42, %40
%44 = trunc i64 %43 to i32
store i32 %44, i32* %14
%45 = load i32, i32* %12
%46 = load i8**, i8*** %10
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load %struct.target*, %struct.target** %9
%49 = call i64 @dump_long_int_from_mem(i32 %45, i8** %47, %struct.target* %48)
%50 = load i32, i32* %14
%51 = sext i32 %50 to i64
%52 = add nsw i64 %51, %49
%53 = trunc i64 %52 to i32
store i32 %53, i32* %14
%54 = load i32, i32* %13
%55 = load i8**, i8*** %10
%56 = getelementptr inbounds i8*, i8** %55, i64 2
%57 = call i64 @dump_ptr(i32 %54, i8** %56)
%58 = load i32, i32* %14
%59 = sext i32 %58 to i64
%60 = add nsw i64 %59, %57
%61 = trunc i64 %60 to i32
store i32 %61, i32* %14
%62 = load i8**, i8*** %10
%63 = call i8* @copy_params(i8** %62, i32 3, i32* %14)
%64 = load i8**, i8*** %8
store i8* %63, i8** %64
%65 = load i8**, i8*** %10
%66 = call i32 @free_dumped_params(i8** %65, i32 3)
%67 = load i32, i32* %14
store i32 %67, i32* %5
br label %109
68: ; preds = %26
%69 = load i32, i32* %6
%70 = icmp sge i32 %69, 1
br i1 %70, label %71, label %102
71: ; preds = %68
%72 = load i32, i32* %6
%73 = load i32, i32* %11
%74 = load i8**, i8*** %10
%75 = getelementptr inbounds i8*, i8** %74, i64 0
%76 = load %struct.target*, %struct.target** %9
%77 = call i64 @dump_robust_list(i32 %72, i32 %73, i8** %75, %struct.target* %76)
%78 = load i32, i32* %14
%79 = sext i32 %78 to i64
%80 = add nsw i64 %79, %77
%81 = trunc i64 %80 to i32
store i32 %81, i32* %14
%82 = load i32, i32* %12
%83 = load i8**, i8*** %10
%84 = getelementptr inbounds i8*, i8** %83, i64 1
%85 = load %struct.target*, %struct.target** %9
%86 = call i64 @dump_long_int_from_mem(i32 %82, i8** %84, %struct.target* %85)
%87 = load i32, i32* %14
%88 = sext i32 %87 to i64
%89 = add nsw i64 %88, %86
%90 = trunc i64 %89 to i32
store i32 %90, i32* %14
%91 = load i32, i32* %6
%92 = sub nsw i32 %91, 1
%93 = load i32, i32* %13
%94 = load i8**, i8*** %10
%95 = getelementptr inbounds i8*, i8** %94, i64 2
%96 = load %struct.target*, %struct.target** %9
%97 = call i64 @dump_robust_list(i32 %92, i32 %93, i8** %95, %struct.target* %96)
%98 = load i32, i32* %14
%99 = sext i32 %98 to i64
%100 = add nsw i64 %99, %97
%101 = trunc i64 %100 to i32
store i32 %101, i32* %14
br label %102
102: ; preds = %71, %68
%103 = load i8**, i8*** %10
%104 = call i8* @copy_params(i8** %103, i32 3, i32* %14)
%105 = load i8**, i8*** %8
store i8* %104, i8** %105
%106 = load i8**, i8*** %10
%107 = call i32 @free_dumped_params(i8** %106, i32 3)
%108 = load i32, i32* %14
store i32 %108, i32* %5
br label %109
109: ; preds = %102, %34, %22
%110 = load i32, i32* %5
ret i32 %110
}

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