#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 sockaddr_ipx {
  int sipx_port;
  int sipx_network;
  int *sipx_node;
  int sipx_type;
  int sipx_zero;
  int /*<<< orphan*/ sipx_family;
};

/* Variables and functions */
int /*<<< orphan*/ PF_IPX;
struct sockaddr_ipx *malloc(int);
int rand();
void gen_ipx(unsigned long *addr, unsigned long *addrlen) {
  struct sockaddr_ipx *ipx;
  unsigned int i;
  ipx = malloc(sizeof(struct sockaddr_ipx));
  if (ipx == NULL)
    return;
  ipx->sipx_family = PF_IPX;
  ipx->sipx_port = rand();
  ipx->sipx_network = rand();
  for (i = 0; i < 6; i++)
    ipx->sipx_node[i] = rand();
  ipx->sipx_type = rand();
  ipx->sipx_zero = rand() % 2;
  *addr = (unsigned long)ipx;
  *addrlen = sizeof(struct sockaddr_ipx);
}


x86 assembly (clang, -O0):
<gen_ipx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x20,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    114e <gen_ipx+0x2e>
jmp    11ef <gen_ipx+0xcf>
mov    0x2e93(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x18(%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)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x6,-0x1c(%rbp)
jae    11b3 <gen_ipx+0x93>
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x1c(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1184 <gen_ipx+0x64>
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
mov    %edx,0x14(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
movq   $0x20,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_ipx>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x20,%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     11d7 <gen_ipx+0xb7>
mov    %rax,%r12
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%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>
mov    0x8(%r12),%rbx
mov    %eax,(%rbx)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,0x4(%rbx)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,0x8(%rbx)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,0xc(%rbx)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,0x10(%rbx)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,0x14(%rbx)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,0x10(%r12)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
sub    %ecx,%eax
mov    %eax,0x14(%r12)
mov    %r12,(%r15)
movq   $0x20,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_ipx = type { i32, i32, i32*, i32, i32, i32 }
@PF_IPX = global i32 0
define void @gen_ipx(i64* %0, i64* %1) {
%3 = alloca i64*
%4 = alloca i64*
%5 = alloca %struct.sockaddr_ipx*
%6 = alloca i32
store i64* %0, i64** %3
store i64* %1, i64** %4
%7 = call %struct.sockaddr_ipx* @malloc(i32 32)
store %struct.sockaddr_ipx* %7, %struct.sockaddr_ipx** %5
%8 = load %struct.sockaddr_ipx*, %struct.sockaddr_ipx** %5
%9 = icmp eq %struct.sockaddr_ipx* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
br label %47
11: ; preds = %2
%12 = load i32, i32* @PF_IPX
%13 = load %struct.sockaddr_ipx*, %struct.sockaddr_ipx** %5
%14 = getelementptr inbounds %struct.sockaddr_ipx, %struct.sockaddr_ipx* %13, i32 0, i32 5
store i32 %12, i32* %14
%15 = call i32 (...) @rand()
%16 = load %struct.sockaddr_ipx*, %struct.sockaddr_ipx** %5
%17 = getelementptr inbounds %struct.sockaddr_ipx, %struct.sockaddr_ipx* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = call i32 (...) @rand()
%19 = load %struct.sockaddr_ipx*, %struct.sockaddr_ipx** %5
%20 = getelementptr inbounds %struct.sockaddr_ipx, %struct.sockaddr_ipx* %19, i32 0, i32 1
store i32 %18, i32* %20
store i32 0, i32* %6
br label %21
21: ; preds = %32, %11
%22 = load i32, i32* %6
%23 = icmp ult i32 %22, 6
br i1 %23, label %24, label %35
24: ; preds = %21
%25 = call i32 (...) @rand()
%26 = load %struct.sockaddr_ipx*, %struct.sockaddr_ipx** %5
%27 = getelementptr inbounds %struct.sockaddr_ipx, %struct.sockaddr_ipx* %26, i32 0, i32 2
%28 = load i32*, i32** %27
%29 = load i32, i32* %6
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
store i32 %25, i32* %31
br label %32
32: ; preds = %24
%33 = load i32, i32* %6
%34 = add i32 %33, 1
store i32 %34, i32* %6
br label %21
35: ; preds = %21
%36 = call i32 (...) @rand()
%37 = load %struct.sockaddr_ipx*, %struct.sockaddr_ipx** %5
%38 = getelementptr inbounds %struct.sockaddr_ipx, %struct.sockaddr_ipx* %37, i32 0, i32 3
store i32 %36, i32* %38
%39 = call i32 (...) @rand()
%40 = srem i32 %39, 2
%41 = load %struct.sockaddr_ipx*, %struct.sockaddr_ipx** %5
%42 = getelementptr inbounds %struct.sockaddr_ipx, %struct.sockaddr_ipx* %41, i32 0, i32 4
store i32 %40, i32* %42
%43 = load %struct.sockaddr_ipx*, %struct.sockaddr_ipx** %5
%44 = ptrtoint %struct.sockaddr_ipx* %43 to i64
%45 = load i64*, i64** %3
store i64 %44, i64* %45
%46 = load i64*, i64** %4
store i64 32, i64* %46
br label %47
47: ; preds = %35, %10
ret void
}

LLVM IR (-O2):
%struct.sockaddr_ipx = type { i32, i32, i32*, i32, i32, i32 }
@PF_IPX = global i32 0
define void @gen_ipx(i64* nocapture writeonly %0, i64* nocapture writeonly %1) {
%3 = tail call %struct.sockaddr_ipx* @malloc(i32 32)
%4 = icmp eq %struct.sockaddr_ipx* %3, null
br i1 %4, label %31, label %5
5: ; preds = %2
%6 = load i32, i32* @PF_IPX
%7 = getelementptr inbounds %struct.sockaddr_ipx, %struct.sockaddr_ipx* %3, i64 0, i32 5
store i32 %6, i32* %7
%8 = tail call i32 (...) @rand()
%9 = getelementptr inbounds %struct.sockaddr_ipx, %struct.sockaddr_ipx* %3, i64 0, i32 0
store i32 %8, i32* %9
%10 = tail call i32 (...) @rand()
%11 = getelementptr inbounds %struct.sockaddr_ipx, %struct.sockaddr_ipx* %3, i64 0, i32 1
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.sockaddr_ipx, %struct.sockaddr_ipx* %3, i64 0, i32 2
%13 = tail call i32 (...) @rand()
%14 = load i32*, i32** %12
store i32 %13, i32* %14
%15 = tail call i32 (...) @rand()
%16 = getelementptr inbounds i32, i32* %14, i64 1
store i32 %15, i32* %16
%17 = tail call i32 (...) @rand()
%18 = getelementptr inbounds i32, i32* %14, i64 2
store i32 %17, i32* %18
%19 = tail call i32 (...) @rand()
%20 = getelementptr inbounds i32, i32* %14, i64 3
store i32 %19, i32* %20
%21 = tail call i32 (...) @rand()
%22 = getelementptr inbounds i32, i32* %14, i64 4
store i32 %21, i32* %22
%23 = tail call i32 (...) @rand()
%24 = getelementptr inbounds i32, i32* %14, i64 5
store i32 %23, i32* %24
%25 = tail call i32 (...) @rand()
%26 = getelementptr inbounds %struct.sockaddr_ipx, %struct.sockaddr_ipx* %3, i64 0, i32 3
store i32 %25, i32* %26
%27 = tail call i32 (...) @rand()
%28 = srem i32 %27, 2
%29 = getelementptr inbounds %struct.sockaddr_ipx, %struct.sockaddr_ipx* %3, i64 0, i32 4
store i32 %28, i32* %29
%30 = ptrtoint %struct.sockaddr_ipx* %3 to i64
store i64 %30, i64* %0
store i64 32, i64* %1
br label %31
31: ; preds = %2, %5
ret void
}