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

/* Variables and functions */
int /*<<< orphan*/ htons(unsigned short);
scalar_t__ malloc(int);
struct sockaddr_in *ws_make_sockaddr_in(short sin_family, unsigned short portno,
                                        int s_addr) {
  struct sockaddr_in *x =
      (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in));
  x->sin_family = sin_family;
  x->sin_port = htons(portno);
  x->sin_addr.s_addr = s_addr;
  return x;
}


x86 assembly (clang, -O0):
<ws_make_sockaddr_in>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %si,%ax
mov    %di,%cx
mov    %cx,-0x2(%rbp)
mov    %ax,-0x4(%rbp)
mov    %edx,-0x8(%rbp)
mov    $0xc,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x2(%rbp),%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
movzwl -0x4(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x8(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ws_make_sockaddr_in>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebx
mov    $0xc,%edi
call   1040 <malloc@plt>
mov    %rax,%rbp
mov    %bx,(%rax)
mov    %r15d,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rbp)
mov    %r14d,0x4(%rbp)
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i16, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
define %struct.sockaddr_in* @ws_make_sockaddr_in(i16 signext %0, i16 zeroext %1, i32 %2) {
%4 = alloca i16
%5 = alloca i16
%6 = alloca i32
%7 = alloca %struct.sockaddr_in*
store i16 %0, i16* %4
store i16 %1, i16* %5
store i32 %2, i32* %6
%8 = call i64 @malloc(i32 12)
%9 = inttoptr i64 %8 to %struct.sockaddr_in*
store %struct.sockaddr_in* %9, %struct.sockaddr_in** %7
%10 = load i16, i16* %4
%11 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i16 %10, i16* %12
%13 = load i16, i16* %5
%14 = call i32 @htons(i16 zeroext %13)
%15 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 2
store i32 %14, i32* %16
%17 = load i32, i32* %6
%18 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %17, i32* %20
%21 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
ret %struct.sockaddr_in* %21
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i16, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
define %struct.sockaddr_in* @ws_make_sockaddr_in(i16 signext %0, i16 zeroext %1, i32 %2) {
%4 = tail call i64 @malloc(i32 12)
%5 = inttoptr i64 %4 to %struct.sockaddr_in*
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i16 %0, i16* %6
%7 = tail call i32 @htons(i16 zeroext %1)
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %2, i32* %9
ret %struct.sockaddr_in* %5
}