#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 utsname {
  char *nodename;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  void *sin_port;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  char *h_name;
  int /*<<< orphan*/ *h_addr_list;
};

/* Variables and functions */
void *AF_INET;
scalar_t__ EADDRINUSE;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ ParseHostname(char *, char *, int);
int /*<<< orphan*/ SOCK_DGRAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
scalar_t__ errno;
struct hostent *gethostbyaddr(char *, int, void *);
struct hostent *gethostbyname(char *);
int getsockname(int, struct sockaddr *, void *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
void *htons(int);
int /*<<< orphan*/ memcpy(TYPE_1__ *, int /*<<< orphan*/, int);
int ntohs(void *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ uname(struct utsname *);
char *MyBestHostname(char *myname, int myname_len, char *display_name,
                     char *dest_url) {
  struct utsname host;
  *myname = '\0';
  if (display_name[0] == ':') {
    struct sockaddr_in local, remote;
    struct hostent *hp;
    int s, rv, namelen;
    char dest_hostname[256 + 1];
    ParseHostname(dest_url, dest_hostname, sizeof dest_hostname);
    hp = gethostbyname(dest_hostname);
    if (hp) {
      memcpy(&remote.sin_addr, hp->h_addr_list[0], sizeof remote.sin_addr);
      remote.sin_port = htons(60000);
      remote.sin_family = AF_INET;
      local.sin_addr.s_addr = htonl(INADDR_ANY);
      local.sin_port = htons(60000);
      local.sin_family = AF_INET;
      s = socket(PF_INET, SOCK_DGRAM, 0);
      if (s != -1) {
        do {
          rv = bind(s, (struct sockaddr *)&local, sizeof local);
          local.sin_port = htons(ntohs(local.sin_port) + 1);
        } while (rv == -1 && errno == EADDRINUSE);
        if (rv != -1) {
          do {
            rv = connect(s, (struct sockaddr *)&remote, sizeof remote);
            remote.sin_port = htons(ntohs(remote.sin_port) + 1);
          } while (rv == -1 && errno == EADDRINUSE);
          if (rv != -1) {
            namelen = sizeof local;
            rv = getsockname(s, (struct sockaddr *)&local, (void *)&namelen);
            if (rv != -1) {
              hp = gethostbyaddr((char *)&local.sin_addr.s_addr,
                                 sizeof local.sin_addr.s_addr, AF_INET);
              if (hp) {
                strncpy(myname, hp->h_name, myname_len);
                myname[256] = '\0';
                close(s);
                return display_name;
              }
            }
          }
        }
        close(s);
      }
    }
    uname(&host);
    strncpy(myname, host.nodename, myname_len);
    myname[256] = '\0';
  } else {
    char *ptr;
    ptr = strchr(display_name, ':');
    if (ptr == NULL) {
      strncpy(myname, display_name, myname_len);
      myname[256] = '\0';
    } else {
      strncpy(myname, display_name, ptr - display_name);
      myname[ptr - display_name] = '\0';
      return ptr;
    }
  }
  return display_name;
}


x86 assembly (clang, -O0):
<MyBestHostname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1489 <MyBestHostname+0x299>
mov    -0x28(%rbp),%rdi
lea    -0x180(%rbp),%rsi
mov    $0x101,%edx
call   1040 <ParseHostname@plt>
lea    -0x180(%rbp),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     1460 <MyBestHostname+0x270>
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    $0x4,%edx
call   10b0 <memcpy@plt>
mov    $0xea60,%edi
call   1050 <htons@plt>
mov    %rax,-0x58(%rbp)
mov    0x2d6a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x48(%rbp)
mov    $0xea60,%edi
call   1050 <htons@plt>
mov    %rax,-0x40(%rbp)
mov    0x2d3d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
mov    0x2d16(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0xffffffff,-0x6c(%rbp)
je     145b <MyBestHostname+0x26b>
jmp    12dd <MyBestHostname+0xed>
mov    -0x6c(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    $0x18,%edx
call   10d0 <bind@plt>
mov    %eax,-0x70(%rbp)
mov    -0x40(%rbp),%rdi
call   10c0 <ntohs@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1050 <htons@plt>
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x70(%rbp)
mov    %al,-0x189(%rbp)
jne    1337 <MyBestHostname+0x147>
mov    0x2c9f(%rip),%rax
mov    (%rax),%rax
mov    0x2c9d(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x189(%rbp)
mov    -0x189(%rbp),%al
test   $0x1,%al
jne    12dd <MyBestHostname+0xed>
cmpl   $0xffffffff,-0x70(%rbp)
je     1453 <MyBestHostname+0x263>
jmp    1354 <MyBestHostname+0x164>
mov    -0x6c(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x18,%edx
call   1100 <connect@plt>
mov    %eax,-0x70(%rbp)
mov    -0x58(%rbp),%rdi
call   10c0 <ntohs@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1050 <htons@plt>
mov    %rax,-0x58(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x70(%rbp)
mov    %al,-0x18a(%rbp)
jne    13ae <MyBestHostname+0x1be>
mov    0x2c28(%rip),%rax
mov    (%rax),%rax
mov    0x2c26(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x18a(%rbp)
mov    -0x18a(%rbp),%al
test   $0x1,%al
jne    1354 <MyBestHostname+0x164>
cmpl   $0xffffffff,-0x70(%rbp)
je     144e <MyBestHostname+0x25e>
movl   $0x18,-0x74(%rbp)
mov    -0x6c(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x74(%rbp),%rdx
call   10e0 <getsockname@plt>
mov    %eax,-0x70(%rbp)
cmpl   $0xffffffff,-0x70(%rbp)
je     1449 <MyBestHostname+0x259>
lea    -0x48(%rbp),%rdi
mov    0x2bf3(%rip),%rax
mov    (%rax),%rdx
mov    $0x4,%esi
call   10f0 <gethostbyaddr@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     1444 <MyBestHostname+0x254>
mov    -0x10(%rbp),%rdi
mov    -0x68(%rbp),%rax
mov    (%rax),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0x100(%rax)
mov    -0x6c(%rbp),%edi
call   1090 <close@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    151c <MyBestHostname+0x32c>
jmp    1449 <MyBestHostname+0x259>
jmp    144e <MyBestHostname+0x25e>
jmp    1453 <MyBestHostname+0x263>
mov    -0x6c(%rbp),%edi
call   1090 <close@plt>
jmp    1460 <MyBestHostname+0x270>
lea    -0x30(%rbp),%rdi
call   1070 <uname@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0x100(%rax)
jmp    1514 <MyBestHostname+0x324>
mov    -0x20(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x188(%rbp)
cmpq   $0x0,-0x188(%rbp)
jne    14cc <MyBestHostname+0x2dc>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0x100(%rax)
jmp    150f <MyBestHostname+0x31f>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x188(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x188(%rbp),%rcx
mov    -0x20(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x188(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    151c <MyBestHostname+0x32c>
jmp    1514 <MyBestHostname+0x324>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x190,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MyBestHostname>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x158,%rsp
mov    %rdx,%r12
mov    %esi,%r15d
mov    %rdi,%r14
movb   $0x0,(%rdi)
cmpb   $0x3a,(%rdx)
jne    13ce <MyBestHostname+0x1de>
lea    0x50(%rsp),%rbx
mov    %rcx,%rdi
mov    %rbx,%rsi
mov    $0x101,%edx
call   1040 <ParseHostname@plt>
mov    %rbx,%rdi
call   10a0 <gethostbyname@plt>
test   %rax,%rax
je     1419 <MyBestHostname+0x229>
mov    0x8(%rax),%rax
mov    (%rax),%esi
lea    0x30(%rsp),%rdi
mov    $0x4,%edx
call   10b0 <memcpy@plt>
mov    $0xea60,%edi
call   1050 <htons@plt>
mov    %rax,0x38(%rsp)
mov    0x2d81(%rip),%rbx
mov    (%rbx),%rax
mov    %rax,0x40(%rsp)
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x18(%rsp)
mov    $0xea60,%edi
call   1050 <htons@plt>
mov    %rax,0x20(%rsp)
mov    (%rbx),%rax
mov    %rax,0x28(%rsp)
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
mov    0x2d30(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
cmp    $0xffffffff,%eax
je     1419 <MyBestHostname+0x229>
mov    %eax,%ebp
mov    %r15d,0x8(%rsp)
mov    %r14,0x10(%rsp)
lea    0x18(%rsp),%r13
mov    0x2cee(%rip),%r15
mov    0x2cef(%rip),%r14
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x18,%edx
call   10d0 <bind@plt>
mov    %eax,%ebx
mov    0x20(%rsp),%rdi
call   10c0 <ntohs@plt>
lea    0x1(%rax),%edi
call   1050 <htons@plt>
mov    %rax,0x20(%rsp)
cmp    $0xffffffff,%ebx
jne    1315 <MyBestHostname+0x125>
mov    (%r14),%rax
cmp    %rax,(%r15)
je     12e0 <MyBestHostname+0xf0>
cmp    $0xffffffff,%ebx
je     1408 <MyBestHostname+0x218>
lea    0x30(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x18,%edx
call   1100 <connect@plt>
mov    %eax,%ebx
mov    0x38(%rsp),%rdi
call   10c0 <ntohs@plt>
lea    0x1(%rax),%edi
call   1050 <htons@plt>
mov    %rax,0x38(%rsp)
cmp    $0xffffffff,%ebx
jne    1365 <MyBestHostname+0x175>
mov    (%r14),%rax
cmp    %rax,(%r15)
je     1330 <MyBestHostname+0x140>
cmp    $0xffffffff,%ebx
je     1408 <MyBestHostname+0x218>
movl   $0x18,0xc(%rsp)
lea    0x18(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
call   10e0 <getsockname@plt>
cmp    $0xffffffff,%eax
je     1408 <MyBestHostname+0x218>
mov    0x2c55(%rip),%rax
mov    (%rax),%rdx
lea    0x18(%rsp),%rdi
mov    $0x4,%esi
call   10f0 <gethostbyaddr@plt>
test   %rax,%rax
je     1408 <MyBestHostname+0x218>
mov    (%rax),%rsi
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    0x8(%rsp),%edx
call   1030 <strncpy@plt>
movb   $0x0,0x100(%rbx)
mov    %ebp,%edi
call   1090 <close@plt>
jmp    143b <MyBestHostname+0x24b>
mov    %r12,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1400 <MyBestHostname+0x210>
mov    %rax,%rbp
mov    %rax,%rbx
sub    %r12,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r14,%rbx,1)
mov    %rbp,%r12
jmp    143b <MyBestHostname+0x24b>
mov    %r14,%rdi
mov    %r12,%rsi
jmp    142b <MyBestHostname+0x23b>
mov    %ebp,%edi
call   1090 <close@plt>
mov    0x10(%rsp),%r14
mov    0x8(%rsp),%r15d
lea    0x48(%rsp),%rdi
call   1070 <uname@plt>
mov    0x48(%rsp),%rsi
mov    %r14,%rdi
mov    %r15d,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x100(%r14)
mov    %r12,%rax
add    $0x158,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.utsname = type { i8* }
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i8*, i32* }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@INADDR_ANY = global i32 0
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@errno = global i64 0
@EADDRINUSE = global i64 0
define i8* @MyBestHostname(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.utsname
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.sockaddr_in
%13 = alloca %struct.hostent*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca [257 x i8]
%18 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%19 = load i8*, i8** %6
store i8 0, i8* %19
%20 = load i8*, i8** %8
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 58
br i1 %24, label %25, label %147
25: ; preds = %4
%26 = load i8*, i8** %9
%27 = getelementptr inbounds [257 x i8], [257 x i8]* %17, i64 0, i64 0
%28 = call i32 @ParseHostname(i8* %26, i8* %27, i32 257)
%29 = getelementptr inbounds [257 x i8], [257 x i8]* %17, i64 0, i64 0
%30 = call %struct.hostent* @gethostbyname(i8* %29)
store %struct.hostent* %30, %struct.hostent** %13
%31 = load %struct.hostent*, %struct.hostent** %13
%32 = icmp ne %struct.hostent* %31, null
br i1 %32, label %33, label %138
33: ; preds = %25
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%35 = load %struct.hostent*, %struct.hostent** %13
%36 = getelementptr inbounds %struct.hostent, %struct.hostent* %35, i32 0, i32 1
%37 = load i32*, i32** %36
%38 = getelementptr inbounds i32, i32* %37, i64 0
%39 = load i32, i32* %38
%40 = call i32 @memcpy(%struct.TYPE_2__* %34, i32 %39, i32 4)
%41 = call i8* @htons(i32 60000)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
store i8* %41, i8** %42
%43 = load i8*, i8** @AF_INET
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i8* %43, i8** %44
%45 = load i32, i32* @INADDR_ANY
%46 = call i32 @htonl(i32 %45)
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%48 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %47, i32 0, i32 0
store i32 %46, i32* %48
%49 = call i8* @htons(i32 60000)
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i8* %49, i8** %50
%51 = load i8*, i8** @AF_INET
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i8* %51, i8** %52
%53 = load i32, i32* @PF_INET
%54 = load i32, i32* @SOCK_DGRAM
%55 = call i32 @socket(i32 %53, i32 %54, i32 0)
store i32 %55, i32* %14
%56 = load i32, i32* %14
%57 = icmp ne i32 %56, -1
br i1 %57, label %58, label %137
58: ; preds = %33
br label %59
59: ; preds = %76, %58
%60 = load i32, i32* %14
%61 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%62 = call i32 @bind(i32 %60, %struct.sockaddr* %61, i32 24)
store i32 %62, i32* %15
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%64 = load i8*, i8** %63
%65 = call i32 @ntohs(i8* %64)
%66 = add nsw i32 %65, 1
%67 = call i8* @htons(i32 %66)
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i8* %67, i8** %68
br label %69
69: ; preds = %59
%70 = load i32, i32* %15
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %76
72: ; preds = %69
%73 = load i64, i64* @errno
%74 = load i64, i64* @EADDRINUSE
%75 = icmp eq i64 %73, %74
br label %76
76: ; preds = %72, %69
%77 = phi i1 [ false, %69 ], [ %75, %72 ]
br i1 %77, label %59, label %78
78: ; preds = %76
%79 = load i32, i32* %15
%80 = icmp ne i32 %79, -1
br i1 %80, label %81, label %134
81: ; preds = %78
br label %82
82: ; preds = %99, %81
%83 = load i32, i32* %14
%84 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%85 = call i32 @connect(i32 %83, %struct.sockaddr* %84, i32 24)
store i32 %85, i32* %15
%86 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%87 = load i8*, i8** %86
%88 = call i32 @ntohs(i8* %87)
%89 = add nsw i32 %88, 1
%90 = call i8* @htons(i32 %89)
%91 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
store i8* %90, i8** %91
br label %92
92: ; preds = %82
%93 = load i32, i32* %15
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %99
95: ; preds = %92
%96 = load i64, i64* @errno
%97 = load i64, i64* @EADDRINUSE
%98 = icmp eq i64 %96, %97
br label %99
99: ; preds = %95, %92
%100 = phi i1 [ false, %92 ], [ %98, %95 ]
br i1 %100, label %82, label %101
101: ; preds = %99
%102 = load i32, i32* %15
%103 = icmp ne i32 %102, -1
br i1 %103, label %104, label %133
104: ; preds = %101
store i32 24, i32* %16
%105 = load i32, i32* %14
%106 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%107 = bitcast i32* %16 to i8*
%108 = call i32 @getsockname(i32 %105, %struct.sockaddr* %106, i8* %107)
store i32 %108, i32* %15
%109 = load i32, i32* %15
%110 = icmp ne i32 %109, -1
br i1 %110, label %111, label %132
111: ; preds = %104
%112 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%113 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %112, i32 0, i32 0
%114 = bitcast i32* %113 to i8*
%115 = load i8*, i8** @AF_INET
%116 = call %struct.hostent* @gethostbyaddr(i8* %114, i32 4, i8* %115)
store %struct.hostent* %116, %struct.hostent** %13
%117 = load %struct.hostent*, %struct.hostent** %13
%118 = icmp ne %struct.hostent* %117, null
br i1 %118, label %119, label %131
119: ; preds = %111
%120 = load i8*, i8** %6
%121 = load %struct.hostent*, %struct.hostent** %13
%122 = getelementptr inbounds %struct.hostent, %struct.hostent* %121, i32 0, i32 0
%123 = load i8*, i8** %122
%124 = load i32, i32* %7
%125 = call i32 @strncpy(i8* %120, i8* %123, i32 %124)
%126 = load i8*, i8** %6
%127 = getelementptr inbounds i8, i8* %126, i64 256
store i8 0, i8* %127
%128 = load i32, i32* %14
%129 = call i32 @close(i32 %128)
%130 = load i8*, i8** %8
store i8* %130, i8** %5
br label %180
131: ; preds = %111
br label %132
132: ; preds = %131, %104
br label %133
133: ; preds = %132, %101
br label %134
134: ; preds = %133, %78
%135 = load i32, i32* %14
%136 = call i32 @close(i32 %135)
br label %137
137: ; preds = %134, %33
br label %138
138: ; preds = %137, %25
%139 = call i32 @uname(%struct.utsname* %10)
%140 = load i8*, i8** %6
%141 = getelementptr inbounds %struct.utsname, %struct.utsname* %10, i32 0, i32 0
%142 = load i8*, i8** %141
%143 = load i32, i32* %7
%144 = call i32 @strncpy(i8* %140, i8* %142, i32 %143)
%145 = load i8*, i8** %6
%146 = getelementptr inbounds i8, i8* %145, i64 256
store i8 0, i8* %146
br label %178
147: ; preds = %4
%148 = load i8*, i8** %8
%149 = call i8* @strchr(i8* %148, i8 signext 58)
store i8* %149, i8** %18
%150 = load i8*, i8** %18
%151 = icmp eq i8* %150, null
br i1 %151, label %152, label %159
152: ; preds = %147
%153 = load i8*, i8** %6
%154 = load i8*, i8** %8
%155 = load i32, i32* %7
%156 = call i32 @strncpy(i8* %153, i8* %154, i32 %155)
%157 = load i8*, i8** %6
%158 = getelementptr inbounds i8, i8* %157, i64 256
store i8 0, i8* %158
br label %177
159: ; preds = %147
%160 = load i8*, i8** %6
%161 = load i8*, i8** %8
%162 = load i8*, i8** %18
%163 = load i8*, i8** %8
%164 = ptrtoint i8* %162 to i64
%165 = ptrtoint i8* %163 to i64
%166 = sub i64 %164, %165
%167 = trunc i64 %166 to i32
%168 = call i32 @strncpy(i8* %160, i8* %161, i32 %167)
%169 = load i8*, i8** %6
%170 = load i8*, i8** %18
%171 = load i8*, i8** %8
%172 = ptrtoint i8* %170 to i64
%173 = ptrtoint i8* %171 to i64
%174 = sub i64 %172, %173
%175 = getelementptr inbounds i8, i8* %169, i64 %174
store i8 0, i8* %175
%176 = load i8*, i8** %18
store i8* %176, i8** %5
br label %180
177: ; preds = %152
br label %178
178: ; preds = %177, %138
%179 = load i8*, i8** %8
store i8* %179, i8** %5
br label %180
180: ; preds = %178, %159, %119
%181 = load i8*, i8** %5
ret i8* %181
}

LLVM IR (-O2):
%struct.utsname = type { i8* }
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i8*, i32* }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@INADDR_ANY = global i32 0
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@errno = global i64 0
@EADDRINUSE = global i64 0
define i8* @MyBestHostname(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca %struct.utsname
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca [257 x i8]
%10 = bitcast %struct.utsname* %5 to i8*
store i8 0, i8* %0
%11 = load i8, i8* %2
%12 = icmp eq i8 %11, 58
br i1 %12, label %13, label %91
13: ; preds = %4
%14 = bitcast %struct.sockaddr_in* %6 to i8*
%15 = bitcast %struct.sockaddr_in* %7 to i8*
%16 = bitcast i32* %8 to i8*
%17 = getelementptr inbounds [257 x i8], [257 x i8]* %9, i64 0, i64 0
%18 = call i32 @ParseHostname(i8* %3, i8* %17, i32 257)
%19 = call %struct.hostent* @gethostbyname(i8* %17)
%20 = icmp eq %struct.hostent* %19, null
br i1 %20, label %85, label %21
21: ; preds = %13
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %19, i64 0, i32 1
%24 = load i32*, i32** %23
%25 = load i32, i32* %24
%26 = call i32 @memcpy(%struct.TYPE_2__* %22, i32 %25, i32 4)
%27 = call i8* @htons(i32 60000)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 1
store i8* %27, i8** %28
%29 = load i8*, i8** @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 2
store i8* %29, i8** %30
%31 = load i32, i32* @INADDR_ANY
%32 = call i32 @htonl(i32 %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0, i32 0
store i32 %32, i32* %33
%34 = call i8* @htons(i32 60000)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1
store i8* %34, i8** %35
%36 = load i8*, i8** @AF_INET
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
store i8* %36, i8** %37
%38 = load i32, i32* @PF_INET
%39 = load i32, i32* @SOCK_DGRAM
%40 = call i32 @socket(i32 %38, i32 %39, i32 0)
%41 = icmp eq i32 %40, -1
br i1 %41, label %85, label %42
42: ; preds = %21
%43 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
br label %44
44: ; preds = %42, %44
%45 = call i32 @bind(i32 %40, %struct.sockaddr* %43, i32 24)
%46 = load i8*, i8** %35
%47 = call i32 @ntohs(i8* %46)
%48 = add nsw i32 %47, 1
%49 = call i8* @htons(i32 %48)
store i8* %49, i8** %35
%50 = icmp eq i32 %45, -1
%51 = load i64, i64* @errno
%52 = load i64, i64* @EADDRINUSE
%53 = icmp eq i64 %51, %52
%54 = select i1 %50, i1 %53, i1 false
br i1 %54, label %44, label %55
55: ; preds = %44
br i1 %50, label %83, label %56
56: ; preds = %55
%57 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
br label %58
58: ; preds = %56, %58
%59 = call i32 @connect(i32 %40, %struct.sockaddr* %57, i32 24)
%60 = load i8*, i8** %28
%61 = call i32 @ntohs(i8* %60)
%62 = add nsw i32 %61, 1
%63 = call i8* @htons(i32 %62)
store i8* %63, i8** %28
%64 = icmp eq i32 %59, -1
%65 = load i64, i64* @errno
%66 = load i64, i64* @EADDRINUSE
%67 = icmp eq i64 %65, %66
%68 = select i1 %64, i1 %67, i1 false
br i1 %68, label %58, label %69
69: ; preds = %58
br i1 %64, label %83, label %70
70: ; preds = %69
store i32 24, i32* %8
%71 = call i32 @getsockname(i32 %40, %struct.sockaddr* %43, i8* %16)
%72 = icmp eq i32 %71, -1
br i1 %72, label %83, label %73
73: ; preds = %70
%74 = load i8*, i8** @AF_INET
%75 = call %struct.hostent* @gethostbyaddr(i8* %14, i32 4, i8* %74)
%76 = icmp eq %struct.hostent* %75, null
br i1 %76, label %83, label %77
77: ; preds = %73
%78 = getelementptr inbounds %struct.hostent, %struct.hostent* %75, i64 0, i32 0
%79 = load i8*, i8** %78
%80 = call i32 @strncpy(i8* %0, i8* %79, i32 %1)
%81 = getelementptr inbounds i8, i8* %0, i64 256
store i8 0, i8* %81
%82 = call i32 @close(i32 %40)
br label %104
83: ; preds = %69, %73, %70, %55
%84 = call i32 @close(i32 %40)
br label %85
85: ; preds = %21, %83, %13
%86 = call i32 @uname(%struct.utsname* %5)
%87 = getelementptr inbounds %struct.utsname, %struct.utsname* %5, i64 0, i32 0
%88 = load i8*, i8** %87
%89 = call i32 @strncpy(i8* %0, i8* %88, i32 %1)
%90 = getelementptr inbounds i8, i8* %0, i64 256
store i8 0, i8* %90
br label %104
91: ; preds = %4
%92 = tail call i8* @strchr(i8* %2, i8 signext 58)
%93 = icmp eq i8* %92, null
br i1 %93, label %94, label %97
94: ; preds = %91
%95 = tail call i32 @strncpy(i8* %0, i8* %2, i32 %1)
%96 = getelementptr inbounds i8, i8* %0, i64 256
store i8 0, i8* %96
br label %104
97: ; preds = %91
%98 = ptrtoint i8* %92 to i64
%99 = ptrtoint i8* %2 to i64
%100 = sub i64 %98, %99
%101 = trunc i64 %100 to i32
%102 = tail call i32 @strncpy(i8* %0, i8* %2, i32 %101)
%103 = getelementptr inbounds i8, i8* %0, i64 %100
store i8 0, i8* %103
br label %104
104: ; preds = %85, %94, %97, %77
%105 = phi i8* [ %2, %77 ], [ %92, %97 ], [ %2, %94 ], [ %2, %85 ]
ret i8* %105
}