#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 **);
int /*<<< orphan*/ free_dumped_params(char **, int);
void *malloc(int);
int dump_old_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_mask = addr + 4;
  unsigned int arm_tracing_sa_flags = addr + 8;
  unsigned int arm_tracing_sa_restorer = 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_mask,
                                           &dumped_type_params[1], target);
    len += dump_long_unsigned_int_from_mem(arm_tracing_sa_flags,
                                           &dumped_type_params[2], target);
    len += dump_ptr(arm_tracing_sa_restorer, &dumped_params[3]);
  }
  *dumped_params = copy_params(dumped_type_params, 4, &len);
  free_dumped_params(dumped_type_params, 4);
  return len;
}


x86 assembly (clang, -O0):
<dump_old_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    11b4 <dump_old_sigaction+0x64>
xor    %edi,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1274 <dump_old_sigaction+0x124>
mov    $0x20,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1244 <dump_old_sigaction+0xf4>
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1050 <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    -0x28(%rbp),%rsi
add    $0x10,%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    -0x38(%rbp),%edi
mov    -0x18(%rbp),%rsi
add    $0x18,%rsi
call   1050 <dump_ptr@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   1060 <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_old_sigaction>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
test   %edi,%edi
js     11ff <dump_old_sigaction+0xaf>
mov    %rcx,%r15
mov    %esi,%ebp
lea    0xc(%rbp),%eax
mov    %eax,0x14(%rsp)
lea    0x8(%rbp),%eax
mov    %eax,0x10(%rsp)
lea    0x4(%rbp),%ebx
mov    $0x20,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %ebp,%edi
mov    %r14,%rsi
call   1050 <dump_ptr@plt>
mov    %rax,%r13
lea    0x8(%r12),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
call   1030 <dump_long_unsigned_int_from_mem@plt>
mov    %rax,%rbp
add    %r13d,%ebp
lea    0x10(%r12),%rsi
mov    0x10(%rsp),%edi
mov    %r15,%rdx
call   1030 <dump_long_unsigned_int_from_mem@plt>
mov    %rax,%rbx
add    %ebp,%ebx
lea    0x18(%r14),%rsi
mov    0x14(%rsp),%edi
call   1050 <dump_ptr@plt>
add    %ebx,%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    %r12,%rdi
mov    $0x4,%esi
call   1060 <copy_params@plt>
mov    %rax,(%r14)
mov    %r12,%rdi
mov    $0x4,%esi
call   1040 <free_dumped_params@plt>
mov    0xc(%rsp),%ebx
jmp    120b <dump_old_sigaction+0xbb>
xor    %ebx,%ebx
xor    %edi,%edi
call   1070 <malloc@plt>
mov    %rax,(%r14)
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_old_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 %76
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 %69
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*** %10
%54 = getelementptr inbounds i8*, i8** %53, i64 2
%55 = load %struct.target*, %struct.target** %9
%56 = call i64 @dump_long_unsigned_int_from_mem(i32 %52, i8** %54, %struct.target* %55)
%57 = load i32, i32* %15
%58 = sext i32 %57 to i64
%59 = add nsw i64 %58, %56
%60 = trunc i64 %59 to i32
store i32 %60, i32* %15
%61 = load i32, i32* %14
%62 = load i8**, i8*** %8
%63 = getelementptr inbounds i8*, i8** %62, i64 3
%64 = call i64 @dump_ptr(i32 %61, i8** %63)
%65 = load i32, i32* %15
%66 = sext i32 %65 to i64
%67 = add nsw i64 %66, %64
%68 = trunc i64 %67 to i32
store i32 %68, i32* %15
br label %69
69: ; preds = %34, %29
%70 = load i8**, i8*** %10
%71 = call i8* @copy_params(i8** %70, i32 4, i32* %15)
%72 = load i8**, i8*** %8
store i8* %71, i8** %72
%73 = load i8**, i8*** %10
%74 = call i32 @free_dumped_params(i8** %73, i32 4)
%75 = load i32, i32* %15
store i32 %75, i32* %5
br label %76
76: ; preds = %69, %25
%77 = load i32, i32* %5
ret i32 %77
}

LLVM IR (-O2):
%struct.target = type { i32 }
define i32 @dump_old_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** %15, i64 2
%23 = tail call i64 @dump_long_unsigned_int_from_mem(i32 %12, i8** %22, %struct.target* %3)
%24 = trunc i64 %23 to i32
%25 = add i32 %21, %24
%26 = getelementptr inbounds i8*, i8** %2, i64 3
%27 = tail call i64 @dump_ptr(i32 %11, i8** %26)
%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
}