#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *gethost(char const *);
int getport(char const *);
int ipv4_hostport(struct sockaddr_in *, char *, int);
int ipv4_endpoint(struct sockaddr_in *sa, const char *ep) {
  int rc, port;
  char *host;
  port = getport(ep);
  host = gethost(ep);
  if (port < 0 || !host) {
    free(host);
    return -1;
  }
  rc = ipv4_hostport(sa, host, port);
  free(host);
  return rc;
}


x86 assembly (clang, -O0):
<ipv4_endpoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <getport@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <gethost@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     117e <ipv4_endpoint+0x3e>
cmpq   $0x0,-0x28(%rbp)
jne    1193 <ipv4_endpoint+0x53>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <ipv4_endpoint+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1060 <ipv4_hostport@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipv4_endpoint>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <getport@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <gethost@plt>
mov    %rax,%rbx
test   %ebp,%ebp
js     1183 <ipv4_endpoint+0x43>
test   %rbx,%rbx
je     1183 <ipv4_endpoint+0x43>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <ipv4_hostport@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
jmp    1190 <ipv4_endpoint+0x50>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
define i32 @ipv4_endpoint(%struct.sockaddr_in* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @getport(i8* %9)
store i32 %10, i32* %7
%11 = load i8*, i8** %5
%12 = call i8* @gethost(i8* %11)
store i8* %12, i8** %8
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = load i8*, i8** %8
%17 = icmp ne i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %15, %2
%19 = load i8*, i8** %8
%20 = call i32 @free(i8* %19)
store i32 -1, i32* %3
br label %29
21: ; preds = %15
%22 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%23 = load i8*, i8** %8
%24 = load i32, i32* %7
%25 = call i32 @ipv4_hostport(%struct.sockaddr_in* %22, i8* %23, i32 %24)
store i32 %25, i32* %6
%26 = load i8*, i8** %8
%27 = call i32 @free(i8* %26)
%28 = load i32, i32* %6
store i32 %28, i32* %3
br label %29
29: ; preds = %21, %18
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
define i32 @ipv4_endpoint(%struct.sockaddr_in* %0, i8* %1) {
%3 = tail call i32 @getport(i8* %1)
%4 = tail call i8* @gethost(i8* %1)
%5 = icmp sgt i32 %3, -1
%6 = icmp ne i8* %4, null
%7 = select i1 %5, i1 %6, i1 false
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @free(i8* %4)
br label %13
10: ; preds = %2
%11 = tail call i32 @ipv4_hostport(%struct.sockaddr_in* %0, i8* %4, i32 %3)
%12 = tail call i32 @free(i8* %4)
br label %13
13: ; preds = %10, %8
%14 = phi i32 [ %11, %10 ], [ -1, %8 ]
ret i32 %14
}