#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_storage {
  int /*<<< orphan*/ ss_family;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
typedef void sockaddr;
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ new_ipstr;
typedef int /*<<< orphan*/ new_addr;
typedef int /*<<< orphan*/ ipstr;
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, void *, int *);
int bind(int, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, void *, char *, int);
int listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char const *argv[]) {
  if (argc != 3) {
    fprintf(stderr, "Usage: showip <hostname> <port>\n");
    return 1;
  }
  struct addrinfo hints, *servinfo;
  int status;
  char ipstr[INET6_ADDRSTRLEN];
  void *addr;
  int sockfd, new_sockfd;
  struct sockaddr_storage new_addr;
  socklen_t new_addrsize;
  char new_ipstr[INET6_ADDRSTRLEN];
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;
  if ((status = getaddrinfo(argv[1], argv[2], &hints, &servinfo)) != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
    return 2;
  }
  struct sockaddr_in *ipv4_addr = (struct sockaddr_in *)servinfo->ai_addr;
  addr = &(ipv4_addr->sin_addr);
  inet_ntop(servinfo->ai_family, addr, ipstr, sizeof(ipstr));
  printf("\tAddress selected: %s\n", ipstr);
  sockfd =
      socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol);
  if (sockfd == -1) {
    perror("\tsocket");
    return 1;
  }
  printf("\tSocket created.\n");
  if (bind(sockfd, servinfo->ai_addr, servinfo->ai_addrlen) == -1) {
    perror("\tbind");
    return 2;
  }
  printf("\tBind successful.\n");
  freeaddrinfo(servinfo);
  if (listen(sockfd, 5) == -1) {
    perror("\tlisten");
    return 3;
  }
  printf("\tWaiting for connections...\n");
  while (1) {
    new_addrsize = sizeof(new_addr);
    new_sockfd = accept(sockfd, (struct sockaddr *)&new_addr, &new_addrsize);
    if (new_sockfd == -1) {
      perror("\taccept");
      return 4;
    }
    inet_ntop(new_addr.ss_family, (struct sockaddr *)&new_addr, new_ipstr,
              sizeof(new_ipstr));
    printf("\tConnection established with %s\n", new_ipstr);
    close(new_sockfd);
    printf("\tConnection closed.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1216 <main+0x46>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14dc <main+0x30c>
mov    0x2dcb(%rip),%rax
mov    (%rax),%ecx
mov    %rcx,-0xa8(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x48(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0xa0(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x50(%rbp)
mov    (%rax),%eax
mov    %rax,-0x98(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x90(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x78(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
je     1306 <main+0x136>
mov    0x2d04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    -0x3c(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0xac(%rbp),%edi
mov    %rax,%rdx
lea    0xd35(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    14d5 <main+0x305>
mov    -0xa0(%rbp),%rdx
mov    -0xa8(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    0x8(%rcx),%rcx
mov    %rcx,-0x88(%rbp)
mov    -0x88(%rbp),%rcx
mov    %rcx,-0x58(%rbp)
mov    -0x38(%rbp),%rcx
mov    0x18(%rcx),%edi
mov    -0x58(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0xa0(%rbp),%rsi
lea    0xce4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
mov    0x18(%rax),%edi
mov    -0x38(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%edx
call   10f0 <socket@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0xffffffff,-0x5c(%rbp)
jne    139b <main+0x1cb>
lea    0xcc6(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    14d5 <main+0x305>
lea    0xcaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x5c(%rbp),%edi
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    13e7 <main+0x217>
lea    0xc94(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x2,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    14d5 <main+0x305>
lea    0xc7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
mov    -0x5c(%rbp),%edi
mov    $0x5,%esi
call   1090 <listen@plt>
cmp    $0xffffffff,%eax
jne    1433 <main+0x263>
lea    0xc61(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x3,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    14d5 <main+0x305>
lea    0xc4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1446 <main+0x276>
movl   $0x4,-0x6c(%rbp)
mov    -0x5c(%rbp),%edi
lea    -0x68(%rbp),%rsi
lea    -0x6c(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,-0x60(%rbp)
cmpl   $0xffffffff,-0x60(%rbp)
jne    1489 <main+0x2b9>
lea    0xc30(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x4,-0x4(%rbp)
movl   $0x1,-0x7c(%rbp)
jmp    14d5 <main+0x305>
mov    -0x90(%rbp),%rdx
mov    -0x98(%rbp),%rax
mov    -0x68(%rbp),%edi
lea    -0x68(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x90(%rbp),%rsi
lea    0xbf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x60(%rbp),%edi
call   1070 <close@plt>
lea    0xc01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1441 <main+0x271>
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
cmp    $0x3,%edi
jne    12a7 <main+0xc7>
mov    %rsi,%rbx
mov    %rsp,-0x38(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%r13
mov    %rcx,-0x50(%rbp)
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r13
mov    %r13,%rsp
mov    (%rax),%r15d
mov    %rsp,%r12
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    -0x70(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1070 <memset@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
lea    -0x48(%rbp),%rcx
mov    %r14,%rdx
call   10e0 <getaddrinfo@plt>
test   %eax,%eax
je     12d2 <main+0xf2>
mov    0x2d53(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1060 <gai_strerror@plt>
lea    0xd94(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x2,%eax
mov    -0x38(%rbp),%rcx
mov    %rcx,%rsp
jmp    12c3 <main+0xe3>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
lea    0xd49(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%r14
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rsi
mov    0x18(%rax),%edi
mov    %r13,%rdx
mov    -0x50(%rbp),%rcx
call   1030 <inet_ntop@plt>
lea    0xd3f(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x48(%rbp),%rax
mov    0x18(%rax),%edi
mov    0x10(%rax),%edx
mov    0x14(%rax),%esi
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
jne    132a <main+0x14a>
lea    0xd2e(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%eax
jmp    129e <main+0xbe>
mov    %eax,%r15d
lea    0xd54(%rip),%rdi
call   1040 <puts@plt>
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rsi
mov    (%rax),%edx
mov    %r15d,%edi
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1361 <main+0x181>
lea    0xcfa(%rip),%rdi
call   10c0 <perror@plt>
jmp    1299 <main+0xb9>
lea    0xd31(%rip),%rdi
call   1040 <puts@plt>
mov    -0x48(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    %r15d,%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    139e <main+0x1be>
lea    0xcc8(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x3,%eax
jmp    129e <main+0xbe>
lea    0xd06(%rip),%rdi
call   1040 <puts@plt>
movl   $0x4,-0x2c(%rbp)
lea    -0x40(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
mov    %r15d,%edi
call   10d0 <accept@plt>
cmp    $0xffffffff,%eax
je     1424 <main+0x244>
mov    %eax,%r13d
lea    -0x40(%rbp),%rbx
nopl   (%rax)
mov    -0x40(%rbp),%edi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r14d,%ecx
call   1030 <inet_ntop@plt>
lea    0xc7f(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13d,%edi
call   1080 <close@plt>
lea    0xcc6(%rip),%rdi
call   1040 <puts@plt>
movl   $0x4,-0x2c(%rbp)
mov    %r15d,%edi
mov    %rbx,%rsi
lea    -0x2c(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
jne    13d0 <main+0x1f0>
lea    0xc34(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x4,%eax
jmp    129e <main+0xbe>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i64, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type opaque
@stderr = global i32 0
@.str = [33 x i8] c"Usage: showip <hostname> <port>\0A\00"
@INET6_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [23 x i8] c"\09Address selected: %s\0A\00"
@.str.3 = [8 x i8] c"\09socket\00"
@.str.4 = [18 x i8] c"\09Socket created.\0A\00"
@.str.5 = [6 x i8] c"\09bind\00"
@.str.6 = [19 x i8] c"\09Bind successful.\0A\00"
@.str.7 = [8 x i8] c"\09listen\00"
@.str.8 = [29 x i8] c"\09Waiting for connections...\0A\00"
@.str.9 = [8 x i8] c"\09accept\00"
@.str.10 = [33 x i8] c"\09Connection established with %s\0A\00"
@.str.11 = [21 x i8] c"\09Connection closed.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.addrinfo
%7 = alloca %struct.addrinfo*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.sockaddr_storage
%15 = alloca i32
%16 = alloca i64
%17 = alloca i32
%18 = alloca %struct.sockaddr_in*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 3
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %126
24: ; preds = %2
%25 = load i32, i32* @INET6_ADDRSTRLEN
%26 = zext i32 %25 to i64
%27 = call i8* @llvm.stacksave()
store i8* %27, i8** %9
%28 = alloca i8, i64 %26
store i64 %26, i64* %10
%29 = load i32, i32* @INET6_ADDRSTRLEN
%30 = zext i32 %29 to i64
%31 = alloca i8, i64 %30
store i64 %30, i64* %16
%32 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 32)
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 4
store i32 %33, i32* %34
%35 = load i32, i32* @SOCK_STREAM
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
store i32 %35, i32* %36
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i32 @getaddrinfo(i8* %39, i8* %42, %struct.addrinfo* %6, %struct.addrinfo** %7)
store i32 %43, i32* %8
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %24
%46 = load i32, i32* @stderr
%47 = load i32, i32* %8
%48 = call i8* @gai_strerror(i32 %47)
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %48)
store i32 2, i32* %3
store i32 1, i32* %17
br label %124
50: ; preds = %24
%51 = load %struct.addrinfo*, %struct.addrinfo** %7
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %51, i32 0, i32 1
%53 = load i64, i64* %52
%54 = inttoptr i64 %53 to %struct.sockaddr_in*
store %struct.sockaddr_in* %54, %struct.sockaddr_in** %18
%55 = load %struct.sockaddr_in*, %struct.sockaddr_in** %18
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %55, i32 0, i32 0
%57 = bitcast i32* %56 to i8*
store i8* %57, i8** %11
%58 = load %struct.addrinfo*, %struct.addrinfo** %7
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %58, i32 0, i32 4
%60 = load i32, i32* %59
%61 = load i8*, i8** %11
%62 = trunc i64 %26 to i32
%63 = call i32 @inet_ntop(i32 %60, i8* %61, i8* %28, i32 %62)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%65 = load %struct.addrinfo*, %struct.addrinfo** %7
%66 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i32 0, i32 4
%67 = load i32, i32* %66
%68 = load %struct.addrinfo*, %struct.addrinfo** %7
%69 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %68, i32 0, i32 3
%70 = load i32, i32* %69
%71 = load %struct.addrinfo*, %struct.addrinfo** %7
%72 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %71, i32 0, i32 2
%73 = load i32, i32* %72
%74 = call i32 @socket(i32 %67, i32 %70, i32 %73)
store i32 %74, i32* %12
%75 = load i32, i32* %12
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %79
77: ; preds = %50
%78 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %17
br label %124
79: ; preds = %50
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%81 = load i32, i32* %12
%82 = load %struct.addrinfo*, %struct.addrinfo** %7
%83 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %82, i32 0, i32 1
%84 = load i64, i64* %83
%85 = load %struct.addrinfo*, %struct.addrinfo** %7
%86 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %85, i32 0, i32 0
%87 = load i32, i32* %86
%88 = call i32 @bind(i32 %81, i64 %84, i32 %87)
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %92
90: ; preds = %79
%91 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i32 2, i32* %3
store i32 1, i32* %17
br label %124
92: ; preds = %79
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%94 = load %struct.addrinfo*, %struct.addrinfo** %7
%95 = call i32 @freeaddrinfo(%struct.addrinfo* %94)
%96 = load i32, i32* %12
%97 = call i32 @listen(i32 %96, i32 5)
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %101
99: ; preds = %92
%100 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
store i32 3, i32* %3
store i32 1, i32* %17
br label %124
101: ; preds = %92
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0))
br label %103
103: ; preds = %113, %101
br label %104
104: ; preds = %103
store i32 4, i32* %15
%105 = load i32, i32* %12
%106 = bitcast %struct.sockaddr_storage* %14 to %struct.sockaddr*
%107 = bitcast %struct.sockaddr* %106 to i8*
%108 = call i32 @accept(i32 %105, i8* %107, i32* %15)
store i32 %108, i32* %13
%109 = load i32, i32* %13
%110 = icmp eq i32 %109, -1
br i1 %110, label %111, label %113
111: ; preds = %104
%112 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
store i32 4, i32* %3
store i32 1, i32* %17
br label %124
113: ; preds = %104
%114 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %14, i32 0, i32 0
%115 = load i32, i32* %114
%116 = bitcast %struct.sockaddr_storage* %14 to %struct.sockaddr*
%117 = bitcast %struct.sockaddr* %116 to i8*
%118 = trunc i64 %30 to i32
%119 = call i32 @inet_ntop(i32 %115, i8* %117, i8* %31, i32 %118)
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0), i8* %31)
%121 = load i32, i32* %13
%122 = call i32 @close(i32 %121)
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0))
br label %103
124: ; preds = %111, %99, %90, %77, %45
%125 = load i8*, i8** %9
br label %126
126: ; preds = %124, %21
%127 = load i32, i32* %3
ret i32 %127
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i64, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
@stderr = global i32 0
@.str = [33 x i8] c"Usage: showip <hostname> <port>\0A\00"
@INET6_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.2 = [23 x i8] c"\09Address selected: %s\0A\00"
@.str.3 = [8 x i8] c"\09socket\00"
@.str.5 = [6 x i8] c"\09bind\00"
@.str.7 = [8 x i8] c"\09listen\00"
@.str.9 = [8 x i8] c"\09accept\00"
@.str.10 = [33 x i8] c"\09Connection established with %s\0A\00"
@str = [17 x i8] c"\09Socket created.\00"
@str.12 = [18 x i8] c"\09Bind successful.\00"
@str.13 = [28 x i8] c"\09Waiting for connections...\00"
@str.14 = [20 x i8] c"\09Connection closed.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca %struct.sockaddr_storage
%6 = alloca i32
%7 = icmp eq i32 %0, 3
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %96
11: ; preds = %2
%12 = bitcast %struct.addrinfo* %3 to i8*
%13 = bitcast %struct.addrinfo** %4 to i8*
%14 = load i32, i32* @INET6_ADDRSTRLEN
%15 = zext i32 %14 to i64
%16 = tail call i8* @llvm.stacksave()
%17 = alloca i8, i64 %15
%18 = bitcast %struct.sockaddr_storage* %5 to i8*
%19 = bitcast i32* %6 to i8*
%20 = load i32, i32* @INET6_ADDRSTRLEN
%21 = zext i32 %20 to i64
%22 = alloca i8, i64 %21
%23 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 32)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %24, i32* %25
%26 = load i32, i32* @SOCK_STREAM
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %26, i32* %27
%28 = getelementptr inbounds i8*, i8** %1, i64 1
%29 = load i8*, i8** %28
%30 = getelementptr inbounds i8*, i8** %1, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @getaddrinfo(i8* %29, i8* %31, %struct.addrinfo* %3, %struct.addrinfo** %4)
%33 = icmp eq i32 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %11
%35 = load i32, i32* @stderr
%36 = call i8* @gai_strerror(i32 %32)
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %36)
br label %94
38: ; preds = %11
%39 = load %struct.addrinfo*, %struct.addrinfo** %4
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i64 0, i32 1
%41 = load i64, i64* %40
%42 = inttoptr i64 %41 to i8*
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i64 0, i32 4
%44 = load i32, i32* %43
%45 = call i32 @inet_ntop(i32 %44, i8* %42, i8* %17, i32 %14)
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%47 = load %struct.addrinfo*, %struct.addrinfo** %4
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i64 0, i32 4
%49 = load i32, i32* %48
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i64 0, i32 3
%51 = load i32, i32* %50
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i64 0, i32 2
%53 = load i32, i32* %52
%54 = call i32 @socket(i32 %49, i32 %51, i32 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %58
56: ; preds = %38
%57 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %94
58: ; preds = %38
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%60 = load %struct.addrinfo*, %struct.addrinfo** %4
%61 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i64 0, i32 1
%62 = load i64, i64* %61
%63 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i64 0, i32 0
%64 = load i32, i32* %63
%65 = call i32 @bind(i32 %54, i64 %62, i32 %64)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %69
67: ; preds = %58
%68 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %94
69: ; preds = %58
%70 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.12, i64 0, i64 0))
%71 = load %struct.addrinfo*, %struct.addrinfo** %4
%72 = call i32 @freeaddrinfo(%struct.addrinfo* %71)
%73 = call i32 @listen(i32 %54, i32 5)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %77
75: ; preds = %69
%76 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %94
77: ; preds = %69
%78 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.13, i64 0, i64 0))
store i32 4, i32* %6
%79 = call i32 @accept(i32 %54, i8* %18, i32* %6)
%80 = icmp eq i32 %79, -1
br i1 %80, label %83, label %81
81: ; preds = %77
%82 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %5, i64 0, i32 0
br label %85
83: ; preds = %85, %77
%84 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
br label %94
85: ; preds = %81, %85
%86 = phi i32 [ %79, %81 ], [ %92, %85 ]
%87 = load i32, i32* %82
%88 = call i32 @inet_ntop(i32 %87, i8* %18, i8* %22, i32 %20)
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0), i8* %22)
%90 = call i32 @close(i32 %86)
%91 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.14, i64 0, i64 0))
store i32 4, i32* %6
%92 = call i32 @accept(i32 %54, i8* %18, i32* %6)
%93 = icmp eq i32 %92, -1
br i1 %93, label %83, label %85
94: ; preds = %56, %67, %75, %83, %34
%95 = phi i32 [ 2, %34 ], [ 1, %56 ], [ 2, %67 ], [ 3, %75 ], [ 4, %83 ]
br label %96
96: ; preds = %94, %8
%97 = phi i32 [ 1, %8 ], [ %95, %94 ]
ret i32 %97
}