#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__ {
  void *net;
  void *station;
};
struct sockaddr_ec {
  void *cookie;
  TYPE_1__ addr;
  void *type;
  void *cb;
  void *port;
  int /*<<< orphan*/ sec_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ PF_ECONET;
struct sockaddr_ec *malloc(int);
void *rand();
void econet_gen_sockaddr(struct sockaddr **addr, socklen_t *addrlen) {
  struct sockaddr_ec *ec;
  ec = malloc(sizeof(struct sockaddr_ec));
  if (ec == NULL)
    return;
  ec->sec_family = PF_ECONET;
  ec->port = rand();
  ec->cb = rand();
  ec->type = rand();
  ec->addr.station = rand();
  ec->addr.net = rand();
  ec->cookie = rand();
  *addr = (struct sockaddr *)ec;
  *addrlen = sizeof(struct sockaddr_ec);
}


x86 assembly (clang, -O0):
<econet_gen_sockaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x38,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    114e <econet_gen_sockaddr+0x2e>
jmp    11de <econet_gen_sockaddr+0xbe>
mov    0x2e93(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x30(%rax)
mov    $0x0,%al
call   1040 <rand@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x28(%rax)
mov    $0x0,%al
call   1040 <rand@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    $0x0,%al
call   1040 <rand@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    $0x0,%al
call   1040 <rand@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    $0x0,%al
call   1040 <rand@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    $0x0,%al
call   1040 <rand@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x38,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<econet_gen_sockaddr>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x38,%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     1194 <econet_gen_sockaddr+0x74>
mov    %rax,%rbx
mov    0x2ea4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rbx)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %rax,0x28(%rbx)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %rax,0x20(%rbx)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %rax,0x18(%rbx)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %rax,0x10(%rbx)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %rax,0x8(%rbx)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %rax,(%rbx)
mov    %rbx,(%r15)
movl   $0x38,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_ec = type { i8*, %struct.TYPE_2__, i8*, i8*, i8*, i32 }
%struct.TYPE_2__ = type { i8*, i8* }
@PF_ECONET = global i32 0
define void @econet_gen_sockaddr(%struct.sockaddr** %0, i32* %1) {
%3 = alloca %struct.sockaddr**
%4 = alloca i32*
%5 = alloca %struct.sockaddr_ec*
store %struct.sockaddr** %0, %struct.sockaddr*** %3
store i32* %1, i32** %4
%6 = call %struct.sockaddr_ec* @malloc(i32 56)
store %struct.sockaddr_ec* %6, %struct.sockaddr_ec** %5
%7 = load %struct.sockaddr_ec*, %struct.sockaddr_ec** %5
%8 = icmp eq %struct.sockaddr_ec* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
br label %38
10: ; preds = %2
%11 = load i32, i32* @PF_ECONET
%12 = load %struct.sockaddr_ec*, %struct.sockaddr_ec** %5
%13 = getelementptr inbounds %struct.sockaddr_ec, %struct.sockaddr_ec* %12, i32 0, i32 5
store i32 %11, i32* %13
%14 = call i8* (...) @rand()
%15 = load %struct.sockaddr_ec*, %struct.sockaddr_ec** %5
%16 = getelementptr inbounds %struct.sockaddr_ec, %struct.sockaddr_ec* %15, i32 0, i32 4
store i8* %14, i8** %16
%17 = call i8* (...) @rand()
%18 = load %struct.sockaddr_ec*, %struct.sockaddr_ec** %5
%19 = getelementptr inbounds %struct.sockaddr_ec, %struct.sockaddr_ec* %18, i32 0, i32 3
store i8* %17, i8** %19
%20 = call i8* (...) @rand()
%21 = load %struct.sockaddr_ec*, %struct.sockaddr_ec** %5
%22 = getelementptr inbounds %struct.sockaddr_ec, %struct.sockaddr_ec* %21, i32 0, i32 2
store i8* %20, i8** %22
%23 = call i8* (...) @rand()
%24 = load %struct.sockaddr_ec*, %struct.sockaddr_ec** %5
%25 = getelementptr inbounds %struct.sockaddr_ec, %struct.sockaddr_ec* %24, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 1
store i8* %23, i8** %26
%27 = call i8* (...) @rand()
%28 = load %struct.sockaddr_ec*, %struct.sockaddr_ec** %5
%29 = getelementptr inbounds %struct.sockaddr_ec, %struct.sockaddr_ec* %28, i32 0, i32 1
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
store i8* %27, i8** %30
%31 = call i8* (...) @rand()
%32 = load %struct.sockaddr_ec*, %struct.sockaddr_ec** %5
%33 = getelementptr inbounds %struct.sockaddr_ec, %struct.sockaddr_ec* %32, i32 0, i32 0
store i8* %31, i8** %33
%34 = load %struct.sockaddr_ec*, %struct.sockaddr_ec** %5
%35 = bitcast %struct.sockaddr_ec* %34 to %struct.sockaddr*
%36 = load %struct.sockaddr**, %struct.sockaddr*** %3
store %struct.sockaddr* %35, %struct.sockaddr** %36
%37 = load i32*, i32** %4
store i32 56, i32* %37
br label %38
38: ; preds = %10, %9
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
%struct.sockaddr_ec = type { i8*, %struct.TYPE_2__, i8*, i8*, i8*, i32 }
%struct.TYPE_2__ = type { i8*, i8* }
@PF_ECONET = global i32 0
define void @econet_gen_sockaddr(%struct.sockaddr** nocapture writeonly %0, i32* nocapture writeonly %1) {
%3 = tail call %struct.sockaddr_ec* @malloc(i32 56)
%4 = icmp eq %struct.sockaddr_ec* %3, null
br i1 %4, label %21, label %5
5: ; preds = %2
%6 = load i32, i32* @PF_ECONET
%7 = getelementptr inbounds %struct.sockaddr_ec, %struct.sockaddr_ec* %3, i64 0, i32 5
store i32 %6, i32* %7
%8 = tail call i8* (...) @rand()
%9 = getelementptr inbounds %struct.sockaddr_ec, %struct.sockaddr_ec* %3, i64 0, i32 4
store i8* %8, i8** %9
%10 = tail call i8* (...) @rand()
%11 = getelementptr inbounds %struct.sockaddr_ec, %struct.sockaddr_ec* %3, i64 0, i32 3
store i8* %10, i8** %11
%12 = tail call i8* (...) @rand()
%13 = getelementptr inbounds %struct.sockaddr_ec, %struct.sockaddr_ec* %3, i64 0, i32 2
store i8* %12, i8** %13
%14 = tail call i8* (...) @rand()
%15 = getelementptr inbounds %struct.sockaddr_ec, %struct.sockaddr_ec* %3, i64 0, i32 1, i32 1
store i8* %14, i8** %15
%16 = tail call i8* (...) @rand()
%17 = getelementptr inbounds %struct.sockaddr_ec, %struct.sockaddr_ec* %3, i64 0, i32 1, i32 0
store i8* %16, i8** %17
%18 = tail call i8* (...) @rand()
%19 = getelementptr inbounds %struct.sockaddr_ec, %struct.sockaddr_ec* %3, i64 0, i32 0
store i8* %18, i8** %19
%20 = bitcast %struct.sockaddr** %0 to %struct.sockaddr_ec**
store %struct.sockaddr_ec* %3, %struct.sockaddr_ec** %20
store i32 56, i32* %1
br label %21
21: ; preds = %2, %5
ret void
}