#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 /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_LOOPBACK;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
struct sockaddr *newAddress() {
  struct sockaddr_in *addr =
      (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in));
  if (addr == NULL) {
    printf("malloc struct sockaddr_in error!\n");
    return NULL;
  }
  bzero(addr, sizeof(struct sockaddr_in));
  addr->sin_family = AF_INET;
  addr->sin_port = htons(8082);
  addr->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  return (struct sockaddr *)addr;
}


x86 assembly (clang, -O0):
<newAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0xc,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118a <newAddress+0x3a>
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d9 <newAddress+0x89>
mov    -0x10(%rbp),%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    $0x1f92,%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newAddress>:
push   %rbx
mov    $0xc,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     119b <newAddress+0x4b>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    $0x1f92,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rbx)
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,(%rbx)
jmp    11a9 <newAddress+0x59>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
@.str = [34 x i8] c"malloc struct sockaddr_in error!\0A\00"
@AF_INET = global i32 0
@INADDR_LOOPBACK = global i32 0
define %struct.sockaddr* @newAddress() {
%1 = alloca %struct.sockaddr*
%2 = alloca %struct.sockaddr_in*
%3 = call i64 @malloc(i32 12)
%4 = inttoptr i64 %3 to %struct.sockaddr_in*
store %struct.sockaddr_in* %4, %struct.sockaddr_in** %2
%5 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%6 = icmp eq %struct.sockaddr_in* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store %struct.sockaddr* null, %struct.sockaddr** %1
br label %25
9: ; preds = %0
%10 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%11 = call i32 @bzero(%struct.sockaddr_in* %10, i32 12)
%12 = load i32, i32* @AF_INET
%13 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 2
store i32 %12, i32* %14
%15 = call i32 @htons(i32 8082)
%16 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 1
store i32 %15, i32* %17
%18 = load i32, i32* @INADDR_LOOPBACK
%19 = call i32 @htonl(i32 %18)
%20 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i32 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %19, i32* %22
%23 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%24 = bitcast %struct.sockaddr_in* %23 to %struct.sockaddr*
store %struct.sockaddr* %24, %struct.sockaddr** %1
br label %25
25: ; preds = %9, %7
%26 = load %struct.sockaddr*, %struct.sockaddr** %1
ret %struct.sockaddr* %26
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@INADDR_LOOPBACK = global i32 0
@str = [33 x i8] c"malloc struct sockaddr_in error!\00"
define %struct.sockaddr* @newAddress() {
%1 = tail call i64 @malloc(i32 12)
%2 = inttoptr i64 %1 to %struct.sockaddr_in*
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %16
6: ; preds = %0
%7 = tail call i32 @bzero(%struct.sockaddr_in* %2, i32 12)
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %8, i32* %9
%10 = tail call i32 @htons(i32 8082)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %10, i32* %11
%12 = load i32, i32* @INADDR_LOOPBACK
%13 = tail call i32 @htonl(i32 %12)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %13, i32* %14
%15 = inttoptr i64 %1 to %struct.sockaddr*
br label %16
16: ; preds = %6, %4
%17 = phi %struct.sockaddr* [ null, %4 ], [ %15, %6 ]
ret %struct.sockaddr* %17
}