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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
struct sockaddr_in *cmalloc(int);
struct in_addr *getHostEntryAddress(char *);
int /*<<< orphan*/ htons(short);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, struct in_addr *, int);
struct sockaddr *createSocketAddress(char *address, short port) {
  struct sockaddr_in *sa = NULL;
  struct in_addr *ia = NULL;
  sa = cmalloc(sizeof(struct sockaddr_in));
  sa->sin_family = AF_INET;
  sa->sin_port = htons(port);
  if (isdigit(address[0]))
    inet_pton(sa->sin_family, address, &sa->sin_addr);
  else {
    ia = getHostEntryAddress(address);
    memcpy(&sa->sin_addr, ia, sizeof(struct in_addr));
  }
  return (struct sockaddr *)sa;
}


x86 assembly (clang, -O0):
<createSocketAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0xc,%edi
call   1070 <cmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e50(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
movswl -0xa(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11e2 <createSocketAddress+0x82>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <inet_pton@plt>
jmp    1201 <createSocketAddress+0xa1>
mov    -0x8(%rbp),%rdi
call   1080 <getHostEntryAddress@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createSocketAddress>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0xc,%edi
call   1070 <cmalloc@plt>
mov    %rax,%rbx
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rbx)
mov    %ebp,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rbx)
movsbl (%r14),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11aa <createSocketAddress+0x4a>
mov    0x4(%rbx),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1060 <inet_pton@plt>
jmp    11c2 <createSocketAddress+0x62>
mov    %r14,%rdi
call   1080 <getHostEntryAddress@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.in_addr = type { i32 }
@AF_INET = global i32 0
define %struct.sockaddr* @createSocketAddress(i8* %0, i16 signext %1) {
%3 = alloca i8*
%4 = alloca i16
%5 = alloca %struct.sockaddr_in*
%6 = alloca %struct.in_addr*
store i8* %0, i8** %3
store i16 %1, i16* %4
store %struct.sockaddr_in* null, %struct.sockaddr_in** %5
store %struct.in_addr* null, %struct.in_addr** %6
%7 = call %struct.sockaddr_in* @cmalloc(i32 12)
store %struct.sockaddr_in* %7, %struct.sockaddr_in** %5
%8 = load i32, i32* @AF_INET
%9 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %8, i32* %10
%11 = load i16, i16* %4
%12 = call i32 @htons(i16 signext %11)
%13 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 2
store i32 %12, i32* %14
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = call i64 @isdigit(i8 signext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %2
%21 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %21, i32 0, i32 1
%23 = load i32, i32* %22
%24 = load i8*, i8** %3
%25 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %25, i32 0, i32 0
%27 = call i32 @inet_pton(i32 %23, i8* %24, i32* %26)
br label %35
28: ; preds = %2
%29 = load i8*, i8** %3
%30 = call %struct.in_addr* @getHostEntryAddress(i8* %29)
store %struct.in_addr* %30, %struct.in_addr** %6
%31 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %31, i32 0, i32 0
%33 = load %struct.in_addr*, %struct.in_addr** %6
%34 = call i32 @memcpy(i32* %32, %struct.in_addr* %33, i32 4)
br label %35
35: ; preds = %28, %20
%36 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%37 = bitcast %struct.sockaddr_in* %36 to %struct.sockaddr*
ret %struct.sockaddr* %37
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.in_addr = type { i32 }
@AF_INET = global i32 0
define %struct.sockaddr* @createSocketAddress(i8* %0, i16 signext %1) {
%3 = tail call %struct.sockaddr_in* @cmalloc(i32 12)
%4 = load i32, i32* @AF_INET
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %4, i32* %5
%6 = tail call i32 @htons(i16 signext %1)
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %6, i32* %7
%8 = load i8, i8* %0
%9 = tail call i64 @isdigit(i8 signext %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i32, i32* %5
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%14 = tail call i32 @inet_pton(i32 %12, i8* %0, i32* %13)
br label %19
15: ; preds = %2
%16 = tail call %struct.in_addr* @getHostEntryAddress(i8* %0)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%18 = tail call i32 @memcpy(i32* %17, %struct.in_addr* %16, i32 4)
br label %19
19: ; preds = %15, %11
%20 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
ret %struct.sockaddr* %20
}