#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_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_ipc_perm(int depth, unsigned int addr, char **dumped_params,
                  struct target *target) {
  char **dumped_type_params;
  unsigned int arm_tracing_key = addr;
  unsigned int arm_tracing_uid = addr + 4;
  unsigned int arm_tracing_gid = addr + 6;
  unsigned int arm_tracing_cuid = addr + 8;
  unsigned int arm_tracing_cgid = addr + 10;
  unsigned int arm_tracing_mode = addr + 12;
  unsigned int arm_tracing_seq = addr + 14;
  int len = 0;
  if (depth < 0) {
    *dumped_params = malloc(0);
    return len;
  }
  dumped_type_params = malloc(7 * (sizeof(char *)));
  if (depth >= 0) {
    len += dump_int_from_mem(arm_tracing_key, &dumped_type_params[0], target);
    len += dump_short_unsigned_int_from_mem(arm_tracing_uid,
                                            &dumped_type_params[1], target);
    len += dump_short_unsigned_int_from_mem(arm_tracing_gid,
                                            &dumped_type_params[2], target);
    len += dump_short_unsigned_int_from_mem(arm_tracing_cuid,
                                            &dumped_type_params[3], target);
    len += dump_short_unsigned_int_from_mem(arm_tracing_cgid,
                                            &dumped_type_params[4], target);
    len += dump_short_unsigned_int_from_mem(arm_tracing_mode,
                                            &dumped_type_params[5], target);
    len += dump_short_unsigned_int_from_mem(arm_tracing_seq,
                                            &dumped_type_params[6], target);
  }
  *dumped_params = copy_params(dumped_type_params, 7, &len);
  free_dumped_params(dumped_type_params, 7);
  return len;
}


x86 assembly (clang, -O0):
<dump_ipc_perm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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    $0x6,%eax
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x38(%rbp)
mov    -0xc(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x3c(%rbp)
mov    -0xc(%rbp),%eax
add    $0xc,%eax
mov    %eax,-0x40(%rbp)
mov    -0xc(%rbp),%eax
add    $0xe,%eax
mov    %eax,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11cf <dump_ipc_perm+0x7f>
xor    %edi,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12fa <dump_ipc_perm+0x1aa>
mov    $0x38,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     12ca <dump_ipc_perm+0x17a>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1070 <dump_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x48(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x48(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%rsi
add    $0x8,%rsi
mov    -0x20(%rbp),%rdx
call   1060 <dump_short_unsigned_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x48(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x48(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x28(%rbp),%rsi
add    $0x10,%rsi
mov    -0x20(%rbp),%rdx
call   1060 <dump_short_unsigned_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x48(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x48(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x28(%rbp),%rsi
add    $0x18,%rsi
mov    -0x20(%rbp),%rdx
call   1060 <dump_short_unsigned_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x48(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x48(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x28(%rbp),%rsi
add    $0x20,%rsi
mov    -0x20(%rbp),%rdx
call   1060 <dump_short_unsigned_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x48(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x48(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x28(%rbp),%rsi
add    $0x28,%rsi
mov    -0x20(%rbp),%rdx
call   1060 <dump_short_unsigned_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x48(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%edi
mov    -0x28(%rbp),%rsi
add    $0x30,%rsi
mov    -0x20(%rbp),%rdx
call   1060 <dump_short_unsigned_int_from_mem@plt>
mov    %rax,%rcx
movslq -0x48(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x7,%esi
lea    -0x48(%rbp),%rdx
call   1040 <copy_params@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
mov    $0x7,%esi
call   1030 <free_dumped_params@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_ipc_perm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%rbp
test   %edi,%edi
js     1264 <dump_ipc_perm+0x114>
mov    %rcx,%r15
mov    %esi,%r13d
lea    0xe(%r13),%eax
mov    %eax,0x1c(%rsp)
lea    0xc(%r13),%eax
mov    %eax,0x18(%rsp)
lea    0xa(%r13),%eax
mov    %eax,0x14(%rsp)
lea    0x8(%r13),%eax
mov    %eax,0x10(%rsp)
lea    0x6(%r13),%ebx
lea    0x4(%r13),%r12d
mov    $0x38,%edi
call   1050 <malloc@plt>
mov    %rbp,0x20(%rsp)
mov    %rax,%r14
mov    %r13d,%edi
mov    %rax,%rsi
mov    %r15,%rdx
call   1070 <dump_int_from_mem@plt>
mov    %rax,%r13
lea    0x8(%r14),%rsi
mov    %r12d,%edi
mov    %r15,%rdx
call   1060 <dump_short_unsigned_int_from_mem@plt>
mov    %rax,%rbp
add    %r13d,%ebp
lea    0x10(%r14),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
call   1060 <dump_short_unsigned_int_from_mem@plt>
mov    %rax,%rbx
add    %ebp,%ebx
lea    0x18(%r14),%rsi
mov    0x10(%rsp),%edi
mov    %r15,%rdx
call   1060 <dump_short_unsigned_int_from_mem@plt>
mov    %rax,%rbp
add    %ebx,%ebp
lea    0x20(%r14),%rsi
mov    0x14(%rsp),%edi
mov    %r15,%rdx
call   1060 <dump_short_unsigned_int_from_mem@plt>
mov    %rax,%rbx
add    %ebp,%ebx
lea    0x28(%r14),%rsi
mov    0x18(%rsp),%edi
mov    %r15,%rdx
call   1060 <dump_short_unsigned_int_from_mem@plt>
mov    %rax,%rbp
add    %ebx,%ebp
lea    0x30(%r14),%rsi
mov    0x1c(%rsp),%edi
mov    %r15,%rdx
call   1060 <dump_short_unsigned_int_from_mem@plt>
add    %ebp,%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
mov    $0x7,%esi
call   1040 <copy_params@plt>
mov    0x20(%rsp),%rcx
mov    %rax,(%rcx)
mov    %r14,%rdi
mov    $0x7,%esi
call   1030 <free_dumped_params@plt>
mov    0xc(%rsp),%ebx
jmp    1271 <dump_ipc_perm+0x121>
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <malloc@plt>
mov    %rax,0x0(%rbp)
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.target = type { i32 }
define i32 @dump_ipc_perm(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
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8** %2, i8*** %8
store %struct.target* %3, %struct.target** %9
%19 = load i32, i32* %7
store i32 %19, i32* %11
%20 = load i32, i32* %7
%21 = add i32 %20, 4
store i32 %21, i32* %12
%22 = load i32, i32* %7
%23 = add i32 %22, 6
store i32 %23, i32* %13
%24 = load i32, i32* %7
%25 = add i32 %24, 8
store i32 %25, i32* %14
%26 = load i32, i32* %7
%27 = add i32 %26, 10
store i32 %27, i32* %15
%28 = load i32, i32* %7
%29 = add i32 %28, 12
store i32 %29, i32* %16
%30 = load i32, i32* %7
%31 = add i32 %30, 14
store i32 %31, i32* %17
store i32 0, i32* %18
%32 = load i32, i32* %6
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %4
%35 = call i8* @malloc(i32 0)
%36 = load i8**, i8*** %8
store i8* %35, i8** %36
%37 = load i32, i32* %18
store i32 %37, i32* %5
br label %114
38: ; preds = %4
%39 = call i8* @malloc(i32 56)
%40 = bitcast i8* %39 to i8**
store i8** %40, i8*** %10
%41 = load i32, i32* %6
%42 = icmp sge i32 %41, 0
br i1 %42, label %43, label %107
43: ; preds = %38
%44 = load i32, i32* %11
%45 = load i8**, i8*** %10
%46 = getelementptr inbounds i8*, i8** %45, i64 0
%47 = load %struct.target*, %struct.target** %9
%48 = call i64 @dump_int_from_mem(i32 %44, i8** %46, %struct.target* %47)
%49 = load i32, i32* %18
%50 = sext i32 %49 to i64
%51 = add nsw i64 %50, %48
%52 = trunc i64 %51 to i32
store i32 %52, i32* %18
%53 = load i32, i32* %12
%54 = load i8**, i8*** %10
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%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* %18
%59 = sext i32 %58 to i64
%60 = add nsw i64 %59, %57
%61 = trunc i64 %60 to i32
store i32 %61, i32* %18
%62 = load i32, i32* %13
%63 = load i8**, i8*** %10
%64 = getelementptr inbounds i8*, i8** %63, i64 2
%65 = load %struct.target*, %struct.target** %9
%66 = call i64 @dump_short_unsigned_int_from_mem(i32 %62, i8** %64, %struct.target* %65)
%67 = load i32, i32* %18
%68 = sext i32 %67 to i64
%69 = add nsw i64 %68, %66
%70 = trunc i64 %69 to i32
store i32 %70, i32* %18
%71 = load i32, i32* %14
%72 = load i8**, i8*** %10
%73 = getelementptr inbounds i8*, i8** %72, i64 3
%74 = load %struct.target*, %struct.target** %9
%75 = call i64 @dump_short_unsigned_int_from_mem(i32 %71, i8** %73, %struct.target* %74)
%76 = load i32, i32* %18
%77 = sext i32 %76 to i64
%78 = add nsw i64 %77, %75
%79 = trunc i64 %78 to i32
store i32 %79, i32* %18
%80 = load i32, i32* %15
%81 = load i8**, i8*** %10
%82 = getelementptr inbounds i8*, i8** %81, i64 4
%83 = load %struct.target*, %struct.target** %9
%84 = call i64 @dump_short_unsigned_int_from_mem(i32 %80, i8** %82, %struct.target* %83)
%85 = load i32, i32* %18
%86 = sext i32 %85 to i64
%87 = add nsw i64 %86, %84
%88 = trunc i64 %87 to i32
store i32 %88, i32* %18
%89 = load i32, i32* %16
%90 = load i8**, i8*** %10
%91 = getelementptr inbounds i8*, i8** %90, i64 5
%92 = load %struct.target*, %struct.target** %9
%93 = call i64 @dump_short_unsigned_int_from_mem(i32 %89, i8** %91, %struct.target* %92)
%94 = load i32, i32* %18
%95 = sext i32 %94 to i64
%96 = add nsw i64 %95, %93
%97 = trunc i64 %96 to i32
store i32 %97, i32* %18
%98 = load i32, i32* %17
%99 = load i8**, i8*** %10
%100 = getelementptr inbounds i8*, i8** %99, i64 6
%101 = load %struct.target*, %struct.target** %9
%102 = call i64 @dump_short_unsigned_int_from_mem(i32 %98, i8** %100, %struct.target* %101)
%103 = load i32, i32* %18
%104 = sext i32 %103 to i64
%105 = add nsw i64 %104, %102
%106 = trunc i64 %105 to i32
store i32 %106, i32* %18
br label %107
107: ; preds = %43, %38
%108 = load i8**, i8*** %10
%109 = call i8* @copy_params(i8** %108, i32 7, i32* %18)
%110 = load i8**, i8*** %8
store i8* %109, i8** %110
%111 = load i8**, i8*** %10
%112 = call i32 @free_dumped_params(i8** %111, i32 7)
%113 = load i32, i32* %18
store i32 %113, i32* %5
br label %114
114: ; preds = %107, %34
%115 = load i32, i32* %5
ret i32 %115
}

LLVM IR (-O2):
%struct.target = type { i32 }
define i32 @dump_ipc_perm(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 %48
10: ; preds = %4
%11 = add i32 %1, 14
%12 = add i32 %1, 12
%13 = add i32 %1, 10
%14 = add i32 %1, 8
%15 = add i32 %1, 6
%16 = add i32 %1, 4
%17 = tail call dereferenceable_or_null(56) i8* @malloc(i32 56)
%18 = bitcast i8* %17 to i8**
%19 = tail call i64 @dump_int_from_mem(i32 %1, i8** %18, %struct.target* %3)
%20 = trunc i64 %19 to i32
%21 = getelementptr inbounds i8*, i8** %18, i64 1
%22 = tail call i64 @dump_short_unsigned_int_from_mem(i32 %16, i8** %21, %struct.target* %3)
%23 = trunc i64 %22 to i32
%24 = add i32 %20, %23
%25 = getelementptr inbounds i8*, i8** %18, i64 2
%26 = tail call i64 @dump_short_unsigned_int_from_mem(i32 %15, i8** %25, %struct.target* %3)
%27 = trunc i64 %26 to i32
%28 = add i32 %24, %27
%29 = getelementptr inbounds i8*, i8** %18, i64 3
%30 = tail call i64 @dump_short_unsigned_int_from_mem(i32 %14, i8** %29, %struct.target* %3)
%31 = trunc i64 %30 to i32
%32 = add i32 %28, %31
%33 = getelementptr inbounds i8*, i8** %18, i64 4
%34 = tail call i64 @dump_short_unsigned_int_from_mem(i32 %13, i8** %33, %struct.target* %3)
%35 = trunc i64 %34 to i32
%36 = add i32 %32, %35
%37 = getelementptr inbounds i8*, i8** %18, i64 5
%38 = tail call i64 @dump_short_unsigned_int_from_mem(i32 %12, i8** %37, %struct.target* %3)
%39 = trunc i64 %38 to i32
%40 = add i32 %36, %39
%41 = getelementptr inbounds i8*, i8** %18, i64 6
%42 = tail call i64 @dump_short_unsigned_int_from_mem(i32 %11, i8** %41, %struct.target* %3)
%43 = trunc i64 %42 to i32
%44 = add i32 %40, %43
store i32 %44, i32* %5
%45 = call i8* @copy_params(i8** %18, i32 7, i32* %5)
store i8* %45, i8** %2
%46 = call i32 @free_dumped_params(i8** %18, i32 7)
%47 = load i32, i32* %5
br label %48
48: ; preds = %10, %8
%49 = phi i32 [ %47, %10 ], [ 0, %8 ]
ret i32 %49
}