#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_char_from_mem(unsigned int, char **, struct target *);
scalar_t__ dump_long_unsigned_int_from_mem(unsigned int, char **,
                                           struct target *);
scalar_t__ dump_short_unsigned_int_from_mem(unsigned int, char **,
                                            struct target *);
int /*<<< orphan*/ free_dumped_params(char **, int);
void *malloc(int);
int dump_linux_dirent(int depth, unsigned int addr, char **dumped_params,
                      struct target *target) {
  char **dumped_type_params;
  unsigned int arm_tracing_d_ino = addr;
  unsigned int arm_tracing_d_off = addr + 4;
  unsigned int arm_tracing_d_reclen = addr + 8;
  unsigned int arm_tracing_d_name = addr + 10;
  int len = 0;
  if (depth < 0) {
    *dumped_params = malloc(0);
    return len;
  }
  dumped_type_params = malloc(4 * (sizeof(char *)));
  if (depth >= 0) {
    len += dump_long_unsigned_int_from_mem(arm_tracing_d_ino,
                                           &dumped_type_params[0], target);
    len += dump_long_unsigned_int_from_mem(arm_tracing_d_off,
                                           &dumped_type_params[1], target);
    len += dump_short_unsigned_int_from_mem(arm_tracing_d_reclen,
                                            &dumped_type_params[2], target);
    len +=
        dump_char_from_mem(arm_tracing_d_name, &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_linux_dirent>:
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    $0xa,%eax
mov    %eax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11c4 <dump_linux_dirent+0x64>
xor    %edi,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128c <dump_linux_dirent+0x12c>
mov    $0x20,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     125c <dump_linux_dirent+0xfc>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%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    -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   1070 <dump_short_unsigned_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x3c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x28(%rbp),%rsi
add    $0x18,%rsi
mov    -0x20(%rbp),%rdx
call   1080 <dump_char_from_mem@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   1050 <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_linux_dirent>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
test   %edi,%edi
js     1219 <dump_linux_dirent+0xb9>
mov    %rcx,%r15
mov    %esi,%ebp
lea    0xa(%rbp),%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rbp),%ebx
lea    0x4(%rbp),%r12d
mov    $0x20,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    %ebp,%edi
mov    %rax,%rsi
mov    %r15,%rdx
call   1030 <dump_long_unsigned_int_from_mem@plt>
mov    %r14,0x10(%rsp)
mov    %rax,%r14
lea    0x8(%r13),%rsi
mov    %r12d,%edi
mov    %r15,%rdx
call   1030 <dump_long_unsigned_int_from_mem@plt>
mov    %rax,%rbp
add    %r14d,%ebp
lea    0x10(%r13),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
call   1070 <dump_short_unsigned_int_from_mem@plt>
mov    %rax,%rbx
add    %ebp,%ebx
lea    0x18(%r13),%rsi
mov    0xc(%rsp),%edi
mov    %r15,%rdx
call   1080 <dump_char_from_mem@plt>
add    %ebx,%eax
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rdx
mov    %r13,%rdi
mov    $0x4,%esi
call   1050 <copy_params@plt>
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx)
mov    %r13,%rdi
mov    $0x4,%esi
call   1040 <free_dumped_params@plt>
mov    0x8(%rsp),%ebx
jmp    1225 <dump_linux_dirent+0xc5>
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <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_linux_dirent(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, 10
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 %78
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 %71
34: ; preds = %29
%35 = load i32, i32* %11
%36 = load i8**, i8*** %10
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = load %struct.target*, %struct.target** %9
%39 = call i64 @dump_long_unsigned_int_from_mem(i32 %35, i8** %37, %struct.target* %38)
%40 = load i32, i32* %15
%41 = sext i32 %40 to i64
%42 = add nsw i64 %41, %39
%43 = trunc i64 %42 to i32
store i32 %43, i32* %15
%44 = load i32, i32* %12
%45 = load i8**, i8*** %10
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load %struct.target*, %struct.target** %9
%48 = call i64 @dump_long_unsigned_int_from_mem(i32 %44, i8** %46, %struct.target* %47)
%49 = load i32, i32* %15
%50 = sext i32 %49 to i64
%51 = add nsw i64 %50, %48
%52 = trunc i64 %51 to i32
store i32 %52, i32* %15
%53 = load i32, i32* %13
%54 = load i8**, i8*** %10
%55 = getelementptr inbounds i8*, i8** %54, i64 2
%56 = load %struct.target*, %struct.target** %9
%57 = call i64 @dump_short_unsigned_int_from_mem(i32 %53, i8** %55, %struct.target* %56)
%58 = load i32, i32* %15
%59 = sext i32 %58 to i64
%60 = add nsw i64 %59, %57
%61 = trunc i64 %60 to i32
store i32 %61, i32* %15
%62 = load i32, i32* %14
%63 = load i8**, i8*** %10
%64 = getelementptr inbounds i8*, i8** %63, i64 3
%65 = load %struct.target*, %struct.target** %9
%66 = call i64 @dump_char_from_mem(i32 %62, i8** %64, %struct.target* %65)
%67 = load i32, i32* %15
%68 = sext i32 %67 to i64
%69 = add nsw i64 %68, %66
%70 = trunc i64 %69 to i32
store i32 %70, i32* %15
br label %71
71: ; preds = %34, %29
%72 = load i8**, i8*** %10
%73 = call i8* @copy_params(i8** %72, i32 4, i32* %15)
%74 = load i8**, i8*** %8
store i8* %73, i8** %74
%75 = load i8**, i8*** %10
%76 = call i32 @free_dumped_params(i8** %75, i32 4)
%77 = load i32, i32* %15
store i32 %77, i32* %5
br label %78
78: ; preds = %71, %25
%79 = load i32, i32* %5
ret i32 %79
}

LLVM IR (-O2):
%struct.target = type { i32 }
define i32 @dump_linux_dirent(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 %33
10: ; preds = %4
%11 = add i32 %1, 10
%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_long_unsigned_int_from_mem(i32 %1, i8** %15, %struct.target* %3)
%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_short_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** %15, i64 3
%27 = tail call i64 @dump_char_from_mem(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
}