#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 */

/* Variables and functions */
unsigned short atoi(char *);
int /*<<< orphan*/ exit(int);
char *index(char *, char);
char *strdup(char *);
void get_ip_port(char **hostname, unsigned short *port, char *hostname_ip) {
  char *semicolon;
  semicolon = index(hostname_ip, ':');
  if ((semicolon == NULL) || (*semicolon != ':'))
    exit(2);
  *semicolon = '\0';
  *hostname = strdup(hostname_ip);
  *port = atoi(semicolon + 1);
}


x86 assembly (clang, -O0):
<get_ip_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <index@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1181 <get_ip_port+0x41>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     118b <get_ip_port+0x4b>
mov    $0x2,%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1040 <atoi@plt>
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ip_port>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
mov    $0x3a,%esi
call   1030 <index@plt>
test   %rax,%rax
je     1195 <get_ip_port+0x55>
mov    %rax,%rbx
cmpb   $0x3a,(%rax)
jne    1195 <get_ip_port+0x55>
movb   $0x0,(%rbx)
mov    %r12,%rdi
call   1060 <strdup@plt>
mov    %rax,(%r15)
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <atoi@plt>
mov    %ax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    $0x2,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
define void @get_ip_port(i8** %0, i16* %1, i8* %2) {
%4 = alloca i8**
%5 = alloca i16*
%6 = alloca i8*
%7 = alloca i8*
store i8** %0, i8*** %4
store i16* %1, i16** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = call i8* @index(i8* %8, i8 signext 58)
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp eq i8* %10, null
br i1 %11, label %17, label %12
12: ; preds = %3
%13 = load i8*, i8** %7
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 58
br i1 %16, label %17, label %19
17: ; preds = %12, %3
%18 = call i32 @exit(i32 2)
unreachable
19: ; preds = %12
%20 = load i8*, i8** %7
store i8 0, i8* %20
%21 = load i8*, i8** %6
%22 = call i8* @strdup(i8* %21)
%23 = load i8**, i8*** %4
store i8* %22, i8** %23
%24 = load i8*, i8** %7
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = call zeroext i16 @atoi(i8* %25)
%27 = load i16*, i16** %5
store i16 %26, i16* %27
ret void
}

LLVM IR (-O2):
define void @get_ip_port(i8** nocapture writeonly %0, i16* nocapture writeonly %1, i8* %2) {
%4 = tail call i8* @index(i8* %2, i8 signext 58)
%5 = icmp eq i8* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = load i8, i8* %4
%8 = icmp eq i8 %7, 58
br i1 %8, label %11, label %9
9: ; preds = %6, %3
%10 = tail call i32 @exit(i32 2)
unreachable
11: ; preds = %6
store i8 0, i8* %4
%12 = tail call i8* @strdup(i8* %2)
store i8* %12, i8** %0
%13 = getelementptr inbounds i8, i8* %4, i64 1
%14 = tail call zeroext i16 @atoi(i8* %13)
store i16 %14, i16* %1
ret void
}