#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_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ HOST_NOT_FOUND;
scalar_t__ NO_ADDRESS;
scalar_t__ NO_DATA;
scalar_t__ NO_RECOVERY;
scalar_t__ TRY_AGAIN;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ errorf(char *, ...);
int /*<<< orphan*/ free(char *);
struct hostent *gethostbyname(char *);
scalar_t__ h_errno;
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
char *strchr(char const *, char);
char *strdup(char const *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
struct sockaddr_in inet_resolve(const char *sockname) {
  struct sockaddr_in sa;
  char *hostname, *netport;
  struct hostent *he;
  if (strchr(sockname, ':') == (0))
    errorf("Internet hostname must be @host:port\n");
  if (!(hostname = strdup(sockname)))
    errorf("Couldn't dup string: %s\n", strerror(errno));
  netport = strchr(hostname, ':');
  *netport = '\0';
  netport++;
  sa.sin_family = AF_INET;
  if (!(he = gethostbyname(hostname)))
    errorf("Couldn't resolve name '%s': %s.\n", hostname,
           (h_errno == HOST_NOT_FOUND) ? "Host not found"
           : ((h_errno == NO_ADDRESS) || (h_errno == NO_DATA))
               ? "No data available"
           : (h_errno == NO_RECOVERY)
               ? "A non-recoverable name server error occured"
           : (h_errno == TRY_AGAIN) ? "A temporary error occured."
                                    : "An unknown error occured");
  memcpy(&(sa.sin_addr), he->h_addr, he->h_length);
  if (!(sa.sin_port = htons(atoi(netport))))
    errorf("Couldn't figure out port number.\n");
  free(hostname);
  return sa;
}


x86 assembly (clang, -O0):
<inet_resolve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
jne    11c2 <inet_resolve+0x32>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1070 <errorf@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11f7 <inet_resolve+0x67>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %eax,%esi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1070 <errorf@plt>
mov    -0x20(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1332 <inet_resolve+0x1a2>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d92(%rip),%rax
mov    (%rax),%rax
mov    0x2d80(%rip),%rcx
cmp    (%rcx),%rax
jne    1271 <inet_resolve+0xe1>
lea    0xdf8(%rip),%rax
mov    %rax,-0x50(%rbp)
jmp    131c <inet_resolve+0x18c>
mov    0x2d68(%rip),%rax
mov    (%rax),%rax
mov    0x2d1e(%rip),%rcx
cmp    (%rcx),%rax
je     12a5 <inet_resolve+0x115>
mov    0x2d4e(%rip),%rax
mov    (%rax),%rax
mov    0x2d14(%rip),%rcx
cmp    (%rcx),%rax
jne    12b5 <inet_resolve+0x125>
lea    0xdc3(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    1314 <inet_resolve+0x184>
mov    0x2d24(%rip),%rax
mov    (%rax),%rax
mov    0x2cfa(%rip),%rcx
cmp    (%rcx),%rax
jne    12df <inet_resolve+0x14f>
lea    0xdab(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    130c <inet_resolve+0x17c>
mov    0x2cfa(%rip),%rax
mov    (%rax),%rdx
mov    0x2cd8(%rip),%rax
mov    (%rax),%rsi
lea    0xdce(%rip),%rax
lea    0xdac(%rip),%rcx
cmp    %rsi,%rdx
cmove  %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%rdx
lea    0xd14(%rip),%rdi
mov    $0x0,%al
call   1070 <errorf@plt>
lea    -0x10(%rbp),%rdi
add    $0x4,%rdi
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
call   1080 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jne    1376 <inet_resolve+0x1e6>
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1070 <errorf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%edx
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_resolve>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    11b9 <inet_resolve+0x29>
lea    0xe4e(%rip),%rdi
xor    %eax,%eax
call   1070 <errorf@plt>
mov    %rbx,%rdi
call   10a0 <strdup@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11e7 <inet_resolve+0x57>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xe48(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <errorf@plt>
mov    %r14,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
add    $0x1,%rbx
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %r14,%rdi
call   1060 <gethostbyname@plt>
mov    %rax,%r15
test   %rax,%rax
jne    129f <inet_resolve+0x10f>
mov    0x2dba(%rip),%rax
mov    (%rax),%rax
mov    0x2da8(%rip),%rcx
cmp    (%rcx),%rax
jne    123e <inet_resolve+0xae>
lea    0xe24(%rip),%rdx
jmp    128e <inet_resolve+0xfe>
mov    0x2d5b(%rip),%rcx
lea    0xe23(%rip),%rdx
cmp    (%rcx),%rax
je     128e <inet_resolve+0xfe>
mov    0x2d58(%rip),%rcx
cmp    (%rcx),%rax
je     128e <inet_resolve+0xfe>
mov    0x2d5c(%rip),%rcx
cmp    (%rcx),%rax
jne    1272 <inet_resolve+0xe2>
lea    0xe11(%rip),%rdx
jmp    128e <inet_resolve+0xfe>
mov    0x2d4f(%rip),%rcx
cmp    (%rcx),%rax
lea    0xe2a(%rip),%rax
lea    0xe3e(%rip),%rdx
cmove  %rax,%rdx
lea    0xdaa(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <errorf@plt>
lea    0x4(%rsp),%rdi
mov    (%r15),%edx
mov    0x4(%r15),%esi
call   1080 <memcpy@plt>
mov    %rbx,%rdi
call   1090 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
test   %eax,%eax
jne    12d4 <inet_resolve+0x144>
lea    0xe14(%rip),%rdi
xor    %eax,%eax
call   1070 <errorf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    (%rsp),%rax
mov    0x8(%rsp),%edx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
@.str = [38 x i8] c"Internet hostname must be @host:port\0A\00"
@.str.1 = [25 x i8] c"Couldn't dup string: %s\0A\00"
@errno = global i32 0
@AF_INET = global i32 0
@.str.2 = [33 x i8] c"Couldn't resolve name '%s': %s.\0A\00"
@h_errno = global i64 0
@HOST_NOT_FOUND = global i64 0
@.str.3 = [15 x i8] c"Host not found\00"
@NO_ADDRESS = global i64 0
@NO_DATA = global i64 0
@.str.4 = [18 x i8] c"No data available\00"
@NO_RECOVERY = global i64 0
@.str.5 = [44 x i8] c"A non-recoverable name server error occured\00"
@TRY_AGAIN = global i64 0
@.str.6 = [27 x i8] c"A temporary error occured.\00"
@.str.7 = [25 x i8] c"An unknown error occured\00"
@.str.8 = [34 x i8] c"Couldn't figure out port number.\0A\00"
define { i64, i32 } @inet_resolve(i8* %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.hostent*
%7 = alloca { i64, i32 }
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i8* @strchr(i8* %8, i8 signext 58)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 (i8*, ...) @errorf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
%14 = load i8*, i8** %3
%15 = call i8* @strdup(i8* %14)
store i8* %15, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i32, i32* @errno
%19 = call i32 @strerror(i32 %18)
%20 = call i32 (i8*, ...) @errorf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %17, %13
%22 = load i8*, i8** %4
%23 = call i8* @strchr(i8* %22, i8 signext 58)
store i8* %23, i8** %5
%24 = load i8*, i8** %5
store i8 0, i8* %24
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %5
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %27, i32* %28
%29 = load i8*, i8** %4
%30 = call %struct.hostent* @gethostbyname(i8* %29)
store %struct.hostent* %30, %struct.hostent** %6
%31 = icmp ne %struct.hostent* %30, null
br i1 %31, label %65, label %32
32: ; preds = %21
%33 = load i8*, i8** %4
%34 = load i64, i64* @h_errno
%35 = load i64, i64* @HOST_NOT_FOUND
%36 = icmp eq i64 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %32
br label %62
38: ; preds = %32
%39 = load i64, i64* @h_errno
%40 = load i64, i64* @NO_ADDRESS
%41 = icmp eq i64 %39, %40
br i1 %41, label %46, label %42
42: ; preds = %38
%43 = load i64, i64* @h_errno
%44 = load i64, i64* @NO_DATA
%45 = icmp eq i64 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %42, %38
br label %60
47: ; preds = %42
%48 = load i64, i64* @h_errno
%49 = load i64, i64* @NO_RECOVERY
%50 = icmp eq i64 %48, %49
br i1 %50, label %51, label %52
51: ; preds = %47
br label %58
52: ; preds = %47
%53 = load i64, i64* @h_errno
%54 = load i64, i64* @TRY_AGAIN
%55 = icmp eq i64 %53, %54
%56 = zext i1 %55 to i64
%57 = select i1 %55, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0)
br label %58
58: ; preds = %52, %51
%59 = phi i8* [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), %51 ], [ %57, %52 ]
br label %60
60: ; preds = %58, %46
%61 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), %46 ], [ %59, %58 ]
br label %62
62: ; preds = %60, %37
%63 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %37 ], [ %61, %60 ]
%64 = call i32 (i8*, ...) @errorf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %33, i8* %63)
br label %65
65: ; preds = %62, %21
%66 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%67 = load %struct.hostent*, %struct.hostent** %6
%68 = getelementptr inbounds %struct.hostent, %struct.hostent* %67, i32 0, i32 1
%69 = load i32, i32* %68
%70 = load %struct.hostent*, %struct.hostent** %6
%71 = getelementptr inbounds %struct.hostent, %struct.hostent* %70, i32 0, i32 0
%72 = load i32, i32* %71
%73 = call i32 @memcpy(i32* %66, i32 %69, i32 %72)
%74 = load i8*, i8** %5
%75 = call i32 @atoi(i8* %74)
%76 = call i32 @htons(i32 %75)
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i32 %76, i32* %77
%78 = icmp ne i32 %76, 0
br i1 %78, label %81, label %79
79: ; preds = %65
%80 = call i32 (i8*, ...) @errorf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0))
br label %81
81: ; preds = %79, %65
%82 = load i8*, i8** %4
%83 = call i32 @free(i8* %82)
%84 = bitcast { i64, i32 }* %7 to i8*
%85 = bitcast %struct.sockaddr_in* %2 to i8*
%86 = load { i64, i32 }, { i64, i32 }* %7
ret { i64, i32 } %86
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
@.str = [38 x i8] c"Internet hostname must be @host:port\0A\00"
@.str.1 = [25 x i8] c"Couldn't dup string: %s\0A\00"
@errno = global i32 0
@AF_INET = global i32 0
@.str.2 = [33 x i8] c"Couldn't resolve name '%s': %s.\0A\00"
@h_errno = global i64 0
@HOST_NOT_FOUND = global i64 0
@.str.3 = [15 x i8] c"Host not found\00"
@NO_ADDRESS = global i64 0
@NO_DATA = global i64 0
@.str.4 = [18 x i8] c"No data available\00"
@NO_RECOVERY = global i64 0
@.str.5 = [44 x i8] c"A non-recoverable name server error occured\00"
@TRY_AGAIN = global i64 0
@.str.6 = [27 x i8] c"A temporary error occured.\00"
@.str.7 = [25 x i8] c"An unknown error occured\00"
@.str.8 = [34 x i8] c"Couldn't figure out port number.\0A\00"
define { i64, i32 } @inet_resolve(i8* %0) {
%2 = alloca %struct.sockaddr_in
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 (i8*, ...) @errorf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %1
%8 = tail call i8* @strdup(i8* %0)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i32, i32* @errno
%12 = tail call i32 @strerror(i32 %11)
%13 = tail call i32 (i8*, ...) @errorf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %10, %7
%15 = tail call i8* @strchr(i8* dereferenceable(1) %8, i8 signext 58)
store i8 0, i8* %15
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %17, i32* %18
%19 = tail call %struct.hostent* @gethostbyname(i8* %8)
%20 = icmp eq %struct.hostent* %19, null
br i1 %20, label %21, label %41
21: ; preds = %14
%22 = load i64, i64* @h_errno
%23 = load i64, i64* @HOST_NOT_FOUND
%24 = icmp eq i64 %22, %23
br i1 %24, label %38, label %25
25: ; preds = %21
%26 = load i64, i64* @NO_ADDRESS
%27 = icmp eq i64 %22, %26
%28 = load i64, i64* @NO_DATA
%29 = icmp eq i64 %22, %28
%30 = select i1 %27, i1 true, i1 %29
br i1 %30, label %38, label %31
31: ; preds = %25
%32 = load i64, i64* @NO_RECOVERY
%33 = icmp eq i64 %22, %32
br i1 %33, label %38, label %34
34: ; preds = %31
%35 = load i64, i64* @TRY_AGAIN
%36 = icmp eq i64 %22, %35
%37 = select i1 %36, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0)
br label %38
38: ; preds = %25, %31, %34, %21
%39 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %21 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), %25 ], [ %37, %34 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), %31 ]
%40 = tail call i32 (i8*, ...) @errorf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* %39)
br label %41
41: ; preds = %38, %14
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
%43 = getelementptr inbounds %struct.hostent, %struct.hostent* %19, i64 0, i32 1
%44 = load i32, i32* %43
%45 = getelementptr inbounds %struct.hostent, %struct.hostent* %19, i64 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 @memcpy(i32* %42, i32 %44, i32 %46)
%48 = call i32 @atoi(i8* %16)
%49 = call i32 @htons(i32 %48)
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %49, i32* %50
%51 = icmp eq i32 %49, 0
br i1 %51, label %52, label %54
52: ; preds = %41
%53 = call i32 (i8*, ...) @errorf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0))
br label %54
54: ; preds = %52, %41
%55 = call i32 @free(i8* %8)
%56 = bitcast %struct.sockaddr_in* %2 to i64*
%57 = load i64, i64* %56
%58 = load i32, i32* %18
%59 = insertvalue { i64, i32 } poison, i64 %57, 0
%60 = insertvalue { i64, i32 } %59, i32 %58, 1
ret { i64, i32 } %60
}