#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 *);
scalar_t__ dump_ptr(unsigned int, char **);
scalar_t__ dump_sigset_t(int, unsigned int, char **, struct target *);
int /*<<< orphan*/ free_dumped_params(char **, int);
void *malloc(int);
int dump_sigaction(int depth, unsigned int addr, char **dumped_params,
                   struct target *target) {
  char **dumped_type_params;
  unsigned int arm_tracing_sa_handler = addr;
  unsigned int arm_tracing_sa_flags = addr + 4;
  unsigned int arm_tracing_sa_restorer = addr + 8;
  unsigned int arm_tracing_sa_mask = addr + 12;
  int len = 0;
  if (depth < 0) {
    *dumped_params = malloc(0);
    return len;
  }
  dumped_type_params = malloc(4 * (sizeof(char *)));
  if (depth >= 0) {
    len += dump_ptr(arm_tracing_sa_handler, &dumped_params[0]);
    len += dump_long_unsigned_int_from_mem(arm_tracing_sa_flags,
                                           &dumped_type_params[1], target);
    len += dump_ptr(arm_tracing_sa_restorer, &dumped_params[2]);
    len += dump_sigset_t(depth, arm_tracing_sa_mask, &dumped_type_params[3],
                         target);
  }
  *dumped_params = copy_params(dumped_type_params, 4, &len);
  free_dumped_params(dumped_type_params, 4);
  return len;
}


x86 assembly (clang, -O0):
<dump_sigaction>:
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)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11c4 <dump_sigaction+0x64>
xor    %edi,%edi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1287 <dump_sigaction+0x127>
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1257 <dump_sigaction+0xf7>
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <dump_ptr@plt>
mov    %rax,%rcx
movslq -0x3c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%rsi
add    $0x8,%rsi
mov    -0x20(%rbp),%rdx
call   1030 <dump_long_unsigned_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x3c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x3c(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x18(%rbp),%rsi
add    $0x10,%rsi
call   1060 <dump_ptr@plt>
mov    %rax,%rcx
movslq -0x3c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x38(%rbp),%esi
mov    -0x28(%rbp),%rdx
add    $0x18,%rdx
mov    -0x20(%rbp),%rcx
call   1050 <dump_sigset_t@plt>
mov    %rax,%rcx
movslq -0x3c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x4,%esi
lea    -0x3c(%rbp),%rdx
call   1070 <copy_params@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
mov    $0x4,%esi
call   1040 <free_dumped_params@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_sigaction>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
test   %edi,%edi
js     121e <dump_sigaction+0xbe>
mov    %esi,%ebp
mov    %edi,%r13d
lea    0xc(%rbp),%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rbp),%eax
mov    %eax,0x8(%rsp)
lea    0x4(%rbp),%eax
mov    %eax,0x4(%rsp)
mov    $0x20,%edi
mov    %rcx,%rbx
mov    %rcx,0x10(%rsp)
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %ebp,%edi
mov    %r15,%rsi
call   1060 <dump_ptr@plt>
mov    %rax,%r14
lea    0x8(%r12),%rsi
mov    0x4(%rsp),%edi
mov    %rbx,%rdx
call   1030 <dump_long_unsigned_int_from_mem@plt>
mov    %rax,%rbp
add    %r14d,%ebp
lea    0x10(%r15),%rsi
mov    0x8(%rsp),%edi
call   1060 <dump_ptr@plt>
mov    %rax,%rbx
add    %ebp,%ebx
lea    0x18(%r12),%rdx
mov    %r13d,%edi
mov    0xc(%rsp),%esi
mov    0x10(%rsp),%rcx
call   1050 <dump_sigset_t@plt>
add    %ebx,%eax
mov    %eax,(%rsp)
mov    %rsp,%rdx
mov    %r12,%rdi
mov    $0x4,%esi
call   1070 <copy_params@plt>
mov    %rax,(%r15)
mov    %r12,%rdi
mov    $0x4,%esi
call   1040 <free_dumped_params@plt>
mov    (%rsp),%ebx
jmp    122a <dump_sigaction+0xca>
xor    %ebx,%ebx
xor    %edi,%edi
call   1080 <malloc@plt>
mov    %rax,(%r15)
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_sigaction(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
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8** %2, i8*** %8
store %struct.target* %3, %struct.target** %9
%16 = load i32, i32* %7
store i32 %16, i32* %11
%17 = load i32, i32* %7
%18 = add i32 %17, 4
store i32 %18, i32* %12
%19 = load i32, i32* %7
%20 = add i32 %19, 8
store i32 %20, i32* %13
%21 = load i32, i32* %7
%22 = add i32 %21, 12
store i32 %22, i32* %14
store i32 0, i32* %15
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %4
%26 = call i8* @malloc(i32 0)
%27 = load i8**, i8*** %8
store i8* %26, i8** %27
%28 = load i32, i32* %15
store i32 %28, i32* %5
br label %77
29: ; preds = %4
%30 = call i8* @malloc(i32 32)
%31 = bitcast i8* %30 to i8**
store i8** %31, i8*** %10
%32 = load i32, i32* %6
%33 = icmp sge i32 %32, 0
br i1 %33, label %34, label %70
34: ; preds = %29
%35 = load i32, i32* %11
%36 = load i8**, i8*** %8
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = call i64 @dump_ptr(i32 %35, i8** %37)
%39 = load i32, i32* %15
%40 = sext i32 %39 to i64
%41 = add nsw i64 %40, %38
%42 = trunc i64 %41 to i32
store i32 %42, i32* %15
%43 = load i32, i32* %12
%44 = load i8**, i8*** %10
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load %struct.target*, %struct.target** %9
%47 = call i64 @dump_long_unsigned_int_from_mem(i32 %43, i8** %45, %struct.target* %46)
%48 = load i32, i32* %15
%49 = sext i32 %48 to i64
%50 = add nsw i64 %49, %47
%51 = trunc i64 %50 to i32
store i32 %51, i32* %15
%52 = load i32, i32* %13
%53 = load i8**, i8*** %8
%54 = getelementptr inbounds i8*, i8** %53, i64 2
%55 = call i64 @dump_ptr(i32 %52, i8** %54)
%56 = load i32, i32* %15
%57 = sext i32 %56 to i64
%58 = add nsw i64 %57, %55
%59 = trunc i64 %58 to i32
store i32 %59, i32* %15
%60 = load i32, i32* %6
%61 = load i32, i32* %14
%62 = load i8**, i8*** %10
%63 = getelementptr inbounds i8*, i8** %62, i64 3
%64 = load %struct.target*, %struct.target** %9
%65 = call i64 @dump_sigset_t(i32 %60, i32 %61, i8** %63, %struct.target* %64)
%66 = load i32, i32* %15
%67 = sext i32 %66 to i64
%68 = add nsw i64 %67, %65
%69 = trunc i64 %68 to i32
store i32 %69, i32* %15
br label %70
70: ; preds = %34, %29
%71 = load i8**, i8*** %10
%72 = call i8* @copy_params(i8** %71, i32 4, i32* %15)
%73 = load i8**, i8*** %8
store i8* %72, i8** %73
%74 = load i8**, i8*** %10
%75 = call i32 @free_dumped_params(i8** %74, i32 4)
%76 = load i32, i32* %15
store i32 %76, i32* %5
br label %77
77: ; preds = %70, %25
%78 = load i32, i32* %5
ret i32 %78
}

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