#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_timespec(int, unsigned int, char **, struct target *);
int /*<<< orphan*/ free_dumped_params(char **, int);
void *malloc(int);
int dump_itimerspec(int depth, unsigned int addr, char **dumped_params,
                    struct target *target) {
  char **dumped_type_params;
  unsigned int anonymous_inner_struct_13 = addr;
  unsigned int anonymous_inner_struct_14 = 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_timespec(depth, anonymous_inner_struct_13,
                         &dumped_type_params[0], target);
    len += dump_timespec(depth, anonymous_inner_struct_14,
                         &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_itimerspec>:
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_itimerspec+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    121e <dump_itimerspec+0xde>
mov    $0x10,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11ee <dump_itimerspec+0xae>
mov    -0x8(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <dump_timespec@plt>
mov    %rax,%rcx
movslq -0x34(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x28(%rbp),%rdx
add    $0x8,%rdx
mov    -0x20(%rbp),%rcx
call   1050 <dump_timespec@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   1040 <copy_params@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
mov    $0x2,%esi
call   1030 <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_itimerspec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
test   %edi,%edi
js     11bc <dump_itimerspec+0x7c>
mov    %rcx,%r15
mov    %esi,%ebx
mov    %edi,%ebp
lea    0x8(%rbx),%r13d
mov    $0x10,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %ebp,%edi
mov    %ebx,%esi
mov    %rax,%rdx
mov    %r15,%rcx
call   1050 <dump_timespec@plt>
mov    %rax,%rbx
lea    0x8(%r12),%rdx
mov    %ebp,%edi
mov    %r13d,%esi
mov    %r15,%rcx
call   1050 <dump_timespec@plt>
add    %ebx,%eax
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %r12,%rdi
mov    $0x2,%esi
call   1040 <copy_params@plt>
mov    %rax,(%r14)
mov    %r12,%rdi
mov    $0x2,%esi
call   1030 <free_dumped_params@plt>
mov    0x4(%rsp),%ebx
jmp    11c8 <dump_itimerspec+0x88>
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <malloc@plt>
mov    %rax,(%r14)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.target = type { i32 }
define i32 @dump_itimerspec(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 %56
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 %49
28: ; preds = %23
%29 = load i32, i32* %6
%30 = load i32, i32* %11
%31 = load i8**, i8*** %10
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load %struct.target*, %struct.target** %9
%34 = call i64 @dump_timespec(i32 %29, i32 %30, i8** %32, %struct.target* %33)
%35 = load i32, i32* %13
%36 = sext i32 %35 to i64
%37 = add nsw i64 %36, %34
%38 = trunc i64 %37 to i32
store i32 %38, i32* %13
%39 = load i32, i32* %6
%40 = load i32, i32* %12
%41 = load i8**, i8*** %10
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load %struct.target*, %struct.target** %9
%44 = call i64 @dump_timespec(i32 %39, i32 %40, i8** %42, %struct.target* %43)
%45 = load i32, i32* %13
%46 = sext i32 %45 to i64
%47 = add nsw i64 %46, %44
%48 = trunc i64 %47 to i32
store i32 %48, i32* %13
br label %49
49: ; preds = %28, %23
%50 = load i8**, i8*** %10
%51 = call i8* @copy_params(i8** %50, i32 2, i32* %13)
%52 = load i8**, i8*** %8
store i8* %51, i8** %52
%53 = load i8**, i8*** %10
%54 = call i32 @free_dumped_params(i8** %53, i32 2)
%55 = load i32, i32* %13
store i32 %55, i32* %5
br label %56
56: ; preds = %49, %19
%57 = load i32, i32* %5
ret i32 %57
}

LLVM IR (-O2):
%struct.target = type { i32 }
define i32 @dump_itimerspec(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_timespec(i32 %0, 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_timespec(i32 %0, 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
}