#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int a_len;
  int *a_addr;
};
struct sockaddr_dn {
  int sdn_flags;
  int sdn_objnum;
  int sdn_objnamel;
  int *sdn_objname;
  TYPE_1__ sdn_add;
  int /*<<< orphan*/ sdn_family;
};

/* Variables and functions */
int /*<<< orphan*/ PF_DECnet;
struct sockaddr_dn *malloc(int);
int rand();
void gen_decnet(unsigned long *addr, unsigned long *addrlen) {
  struct sockaddr_dn *dn;
  unsigned int i;
  dn = malloc(sizeof(struct sockaddr_dn));
  if (dn == NULL)
    return;
  dn->sdn_family = PF_DECnet;
  dn->sdn_flags = rand();
  dn->sdn_objnum = rand();
  dn->sdn_objnamel = rand() % 16;
  for (i = 0; i < dn->sdn_objnamel; i++)
    dn->sdn_objname[i] = rand();
  dn->sdn_add.a_len = rand() % 2;
  dn->sdn_add.a_addr[0] = rand();
  dn->sdn_add.a_addr[1] = rand();
  *addr = (unsigned long)dn;
  *addrlen = sizeof(struct sockaddr_dn);
}


x86 assembly (clang, -O0):
<gen_decnet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x30,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    114e <gen_decnet+0x2e>
jmp    1222 <gen_decnet+0x102>
mov    0x2e8b(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x28(%rax)
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
mov    %edx,0x8(%rax)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    0x8(%rcx),%eax
jae    11cf <gen_decnet+0xaf>
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    -0x1c(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119a <gen_decnet+0x7a>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
mov    %edx,0x18(%rax)
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%rax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
movq   $0x30,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_decnet>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x30,%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     11e7 <gen_decnet+0xc7>
mov    %rax,%r12
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%r12)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,(%r12)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,0x4(%r12)
xor    %eax,%eax
call   1040 <rand@plt>
lea    0xf(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffff0,%ecx
sub    %ecx,%eax
mov    %eax,0x8(%r12)
je     11ad <gen_decnet+0x8d>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
mov    0x10(%r12),%rcx
mov    %eax,(%rcx,%rbx,4)
add    $0x1,%rbx
mov    0x8(%r12),%eax
cmp    %rax,%rbx
jb     1190 <gen_decnet+0x70>
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
sub    %ecx,%eax
mov    %eax,0x18(%r12)
xor    %eax,%eax
call   1040 <rand@plt>
mov    0x20(%r12),%rbx
mov    %eax,(%rbx)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,0x4(%rbx)
mov    %r12,(%r15)
movq   $0x30,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_dn = type { i32, i32, i32, i32*, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32, i32* }
@PF_DECnet = global i32 0
define void @gen_decnet(i64* %0, i64* %1) {
%3 = alloca i64*
%4 = alloca i64*
%5 = alloca %struct.sockaddr_dn*
%6 = alloca i32
store i64* %0, i64** %3
store i64* %1, i64** %4
%7 = call %struct.sockaddr_dn* @malloc(i32 48)
store %struct.sockaddr_dn* %7, %struct.sockaddr_dn** %5
%8 = load %struct.sockaddr_dn*, %struct.sockaddr_dn** %5
%9 = icmp eq %struct.sockaddr_dn* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
br label %64
11: ; preds = %2
%12 = load i32, i32* @PF_DECnet
%13 = load %struct.sockaddr_dn*, %struct.sockaddr_dn** %5
%14 = getelementptr inbounds %struct.sockaddr_dn, %struct.sockaddr_dn* %13, i32 0, i32 5
store i32 %12, i32* %14
%15 = call i32 (...) @rand()
%16 = load %struct.sockaddr_dn*, %struct.sockaddr_dn** %5
%17 = getelementptr inbounds %struct.sockaddr_dn, %struct.sockaddr_dn* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = call i32 (...) @rand()
%19 = load %struct.sockaddr_dn*, %struct.sockaddr_dn** %5
%20 = getelementptr inbounds %struct.sockaddr_dn, %struct.sockaddr_dn* %19, i32 0, i32 1
store i32 %18, i32* %20
%21 = call i32 (...) @rand()
%22 = srem i32 %21, 16
%23 = load %struct.sockaddr_dn*, %struct.sockaddr_dn** %5
%24 = getelementptr inbounds %struct.sockaddr_dn, %struct.sockaddr_dn* %23, i32 0, i32 2
store i32 %22, i32* %24
store i32 0, i32* %6
br label %25
25: ; preds = %39, %11
%26 = load i32, i32* %6
%27 = load %struct.sockaddr_dn*, %struct.sockaddr_dn** %5
%28 = getelementptr inbounds %struct.sockaddr_dn, %struct.sockaddr_dn* %27, i32 0, i32 2
%29 = load i32, i32* %28
%30 = icmp ult i32 %26, %29
br i1 %30, label %31, label %42
31: ; preds = %25
%32 = call i32 (...) @rand()
%33 = load %struct.sockaddr_dn*, %struct.sockaddr_dn** %5
%34 = getelementptr inbounds %struct.sockaddr_dn, %struct.sockaddr_dn* %33, i32 0, i32 3
%35 = load i32*, i32** %34
%36 = load i32, i32* %6
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
store i32 %32, i32* %38
br label %39
39: ; preds = %31
%40 = load i32, i32* %6
%41 = add i32 %40, 1
store i32 %41, i32* %6
br label %25
42: ; preds = %25
%43 = call i32 (...) @rand()
%44 = srem i32 %43, 2
%45 = load %struct.sockaddr_dn*, %struct.sockaddr_dn** %5
%46 = getelementptr inbounds %struct.sockaddr_dn, %struct.sockaddr_dn* %45, i32 0, i32 4
%47 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %46, i32 0, i32 0
store i32 %44, i32* %47
%48 = call i32 (...) @rand()
%49 = load %struct.sockaddr_dn*, %struct.sockaddr_dn** %5
%50 = getelementptr inbounds %struct.sockaddr_dn, %struct.sockaddr_dn* %49, i32 0, i32 4
%51 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %50, i32 0, i32 1
%52 = load i32*, i32** %51
%53 = getelementptr inbounds i32, i32* %52, i64 0
store i32 %48, i32* %53
%54 = call i32 (...) @rand()
%55 = load %struct.sockaddr_dn*, %struct.sockaddr_dn** %5
%56 = getelementptr inbounds %struct.sockaddr_dn, %struct.sockaddr_dn* %55, i32 0, i32 4
%57 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %56, i32 0, i32 1
%58 = load i32*, i32** %57
%59 = getelementptr inbounds i32, i32* %58, i64 1
store i32 %54, i32* %59
%60 = load %struct.sockaddr_dn*, %struct.sockaddr_dn** %5
%61 = ptrtoint %struct.sockaddr_dn* %60 to i64
%62 = load i64*, i64** %3
store i64 %61, i64* %62
%63 = load i64*, i64** %4
store i64 48, i64* %63
br label %64
64: ; preds = %42, %10
ret void
}

LLVM IR (-O2):
%struct.sockaddr_dn = type { i32, i32, i32, i32*, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32, i32* }
@PF_DECnet = global i32 0
define void @gen_decnet(i64* nocapture writeonly %0, i64* nocapture writeonly %1) {
%3 = tail call %struct.sockaddr_dn* @malloc(i32 48)
%4 = icmp eq %struct.sockaddr_dn* %3, null
br i1 %4, label %37, label %5
5: ; preds = %2
%6 = load i32, i32* @PF_DECnet
%7 = getelementptr inbounds %struct.sockaddr_dn, %struct.sockaddr_dn* %3, i64 0, i32 5
store i32 %6, i32* %7
%8 = tail call i32 (...) @rand()
%9 = getelementptr inbounds %struct.sockaddr_dn, %struct.sockaddr_dn* %3, i64 0, i32 0
store i32 %8, i32* %9
%10 = tail call i32 (...) @rand()
%11 = getelementptr inbounds %struct.sockaddr_dn, %struct.sockaddr_dn* %3, i64 0, i32 1
store i32 %10, i32* %11
%12 = tail call i32 (...) @rand()
%13 = srem i32 %12, 16
%14 = getelementptr inbounds %struct.sockaddr_dn, %struct.sockaddr_dn* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = icmp eq i32 %13, 0
br i1 %15, label %27, label %16
16: ; preds = %5
%17 = getelementptr inbounds %struct.sockaddr_dn, %struct.sockaddr_dn* %3, i64 0, i32 3
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 0, %16 ], [ %23, %18 ]
%20 = tail call i32 (...) @rand()
%21 = load i32*, i32** %17
%22 = getelementptr inbounds i32, i32* %21, i64 %19
store i32 %20, i32* %22
%23 = add nuw nsw i64 %19, 1
%24 = load i32, i32* %14
%25 = zext i32 %24 to i64
%26 = icmp ult i64 %23, %25
br i1 %26, label %18, label %27
27: ; preds = %18, %5
%28 = tail call i32 (...) @rand()
%29 = srem i32 %28, 2
%30 = getelementptr inbounds %struct.sockaddr_dn, %struct.sockaddr_dn* %3, i64 0, i32 4, i32 0
store i32 %29, i32* %30
%31 = tail call i32 (...) @rand()
%32 = getelementptr inbounds %struct.sockaddr_dn, %struct.sockaddr_dn* %3, i64 0, i32 4, i32 1
%33 = load i32*, i32** %32
store i32 %31, i32* %33
%34 = tail call i32 (...) @rand()
%35 = getelementptr inbounds i32, i32* %33, i64 1
store i32 %34, i32* %35
%36 = ptrtoint %struct.sockaddr_dn* %3 to i64
store i64 %36, i64* %0
store i64 48, i64* %1
br label %37
37: ; preds = %2, %27
ret void
}