#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_msghdr(int, unsigned int, char **, struct target *);
scalar_t__ dump_unsigned_int_from_mem(unsigned int, char **, struct target *);
int /*<<< orphan*/ free_dumped_params(char **, int);
void *malloc(int);
int dump_mmsghdr(int depth, unsigned int addr, char **dumped_params,
                 struct target *target) {
  char **dumped_type_params;
  unsigned int anonymous_inner_struct_33 = addr;
  unsigned int arm_tracing_msg_len = addr + 28;
  int len = 0;
  if (depth < 0) {
    *dumped_params = malloc(0);
    return len;
  }
  dumped_type_params = malloc(2 * (sizeof(char *)));
  if (depth >= 0) {
    len += dump_msghdr(depth, anonymous_inner_struct_33, &dumped_type_params[0],
                       target);
    len += dump_unsigned_int_from_mem(arm_tracing_msg_len,
                                      &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_mmsghdr>:
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    $0x1c,%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11a2 <dump_mmsghdr+0x52>
xor    %edi,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    122b <dump_mmsghdr+0xdb>
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11fb <dump_mmsghdr+0xab>
mov    -0x8(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1070 <dump_msghdr@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   1060 <dump_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   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_mmsghdr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
test   %edi,%edi
js     11ca <dump_mmsghdr+0x7a>
mov    %rcx,%r15
mov    %esi,%ebx
mov    %edi,%ebp
lea    0x1c(%rbx),%r13d
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %ebp,%edi
mov    %ebx,%esi
mov    %rax,%rdx
mov    %r15,%rcx
call   1070 <dump_msghdr@plt>
mov    %rax,%rbx
lea    0x8(%r12),%rsi
mov    %r13d,%edi
mov    %r15,%rdx
call   1060 <dump_unsigned_int_from_mem@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    11d6 <dump_mmsghdr+0x86>
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <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_mmsghdr(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, 28
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 %55
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 %48
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_msghdr(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* %12
%40 = load i8**, i8*** %10
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load %struct.target*, %struct.target** %9
%43 = call i64 @dump_unsigned_int_from_mem(i32 %39, i8** %41, %struct.target* %42)
%44 = load i32, i32* %13
%45 = sext i32 %44 to i64
%46 = add nsw i64 %45, %43
%47 = trunc i64 %46 to i32
store i32 %47, i32* %13
br label %48
48: ; preds = %28, %23
%49 = load i8**, i8*** %10
%50 = call i8* @copy_params(i8** %49, i32 2, i32* %13)
%51 = load i8**, i8*** %8
store i8* %50, i8** %51
%52 = load i8**, i8*** %10
%53 = call i32 @free_dumped_params(i8** %52, i32 2)
%54 = load i32, i32* %13
store i32 %54, i32* %5
br label %55
55: ; preds = %48, %19
%56 = load i32, i32* %5
ret i32 %56
}

LLVM IR (-O2):
%struct.target = type { i32 }
define i32 @dump_mmsghdr(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, 28
%12 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%13 = bitcast i8* %12 to i8**
%14 = tail call i64 @dump_msghdr(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_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
}