#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 TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
typedef int /*<<< orphan*/ ip;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int INET_ADDRSTRLEN;
short atoi(char const *);
int /*<<< orphan*/ htons(short);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
struct sockaddr_in parseIp(const char *ip_port) {
  struct sockaddr_in saddr;
  char ip[INET_ADDRSTRLEN];
  short int port;
  int i;
  memset(ip, 0, sizeof(ip) / sizeof(*ip));
  for (i = 0; *ip_port != 0; ++i) {
    if (*ip_port == ':') {
      ++ip_port;
      break;
    }
    ip[i] = *ip_port;
    ++ip_port;
  }
  port = atoi(ip_port);
  saddr.sin_family = AF_INET;
  saddr.sin_port = htons(port);
  saddr.sin_addr.s_addr = inet_addr(ip);
  printf("ip %s\n", ip);
  printf("port %d\n", (int)port);
  return (saddr);
}


x86 assembly (clang, -O0):
<parseIp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x18(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
shr    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f8 <parseIp+0xa8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    11cd <parseIp+0x7d>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11f8 <parseIp+0xa8>
mov    -0x48(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%dl
movslq -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    119c <parseIp+0x4c>
mov    -0x18(%rbp),%rdi
call   1070 <atoi@plt>
mov    %ax,-0x2a(%rbp)
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
movswl -0x2a(%rbp),%edi
call   1030 <htons@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,-0xc(%rbp)
call   1060 <inet_addr@plt>
mov    -0x48(%rbp),%rsi
mov    %eax,-0x10(%rbp)
lea    0xdcc(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x49(%rbp)
call   1040 <printf@plt>
mov    -0x49(%rbp),%al
movswl -0x2a(%rbp),%esi
lea    0xdbb(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%edx
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseIp>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r14
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %r14,%rax
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%ecx
test   %cl,%cl
je     11ac <parseIp+0x5c>
cmp    $0x3a,%cl
je     11a8 <parseIp+0x58>
mov    %cl,(%rax)
add    $0x1,%rbx
add    $0x1,%rax
jmp    1190 <parseIp+0x40>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1070 <atoi@plt>
mov    0x2e2d(%rip),%rcx
mov    (%rcx),%r15d
movswl %ax,%r12d
mov    %r12d,%edi
call   1030 <htons@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1060 <inet_addr@plt>
mov    %eax,%r13d
lea    0xe22(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe18(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
shl    $0x20,%rbx
mov    %r13d,%eax
or     %rbx,%rax
mov    %r15d,%edx
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
@INET_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@.str = [7 x i8] c"ip %s\0A\00"
@.str.1 = [9 x i8] c"port %d\0A\00"
define { i64, i32 } @parseIp(i8* %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i16
%7 = alloca i32
%8 = alloca { i64, i32 }
store i8* %0, i8** %3
%9 = load i32, i32* @INET_ADDRSTRLEN
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i8, i64 %10
store i64 %10, i64* %5
%13 = udiv i64 %10, 1
%14 = trunc i64 %13 to i32
%15 = call i32 @memset(i8* %12, i32 0, i32 %14)
store i32 0, i32* %7
br label %16
16: ; preds = %37, %1
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %40
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 58
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %3
br label %40
29: ; preds = %21
%30 = load i8*, i8** %3
%31 = load i8, i8* %30
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %12, i64 %33
store i8 %31, i8* %34
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %3
br label %37
37: ; preds = %29
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %16
40: ; preds = %26, %16
%41 = load i8*, i8** %3
%42 = call signext i16 @atoi(i8* %41)
store i16 %42, i16* %6
%43 = load i32, i32* @AF_INET
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %43, i32* %44
%45 = load i16, i16* %6
%46 = call i32 @htons(i16 signext %45)
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
store i32 %46, i32* %47
%48 = call i32 @inet_addr(i8* %12)
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
%50 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %49, i32 0, i32 0
store i32 %48, i32* %50
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %12)
%52 = load i16, i16* %6
%53 = sext i16 %52 to i32
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %53)
%55 = load i8*, i8** %4
%56 = bitcast { i64, i32 }* %8 to i8*
%57 = bitcast %struct.sockaddr_in* %2 to i8*
%58 = load { i64, i32 }, { i64, i32 }* %8
ret { i64, i32 } %58
}

LLVM IR (-O2):
@INET_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@.str = [7 x i8] c"ip %s\0A\00"
@.str.1 = [9 x i8] c"port %d\0A\00"
define { i64, i32 } @parseIp(i8* nocapture %0) {
%2 = load i32, i32* @INET_ADDRSTRLEN
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i32 @memset(i8* %4, i32 0, i32 %2)
br label %6
6: ; preds = %12, %1
%7 = phi i64 [ %15, %12 ], [ 0, %1 ]
%8 = phi i8* [ %14, %12 ], [ %0, %1 ]
%9 = load i8, i8* %8
switch i8 %9, label %12 [
i8 0, label %16
i8 58, label %10
]
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %8, i64 1
br label %16
12: ; preds = %6
%13 = getelementptr inbounds i8, i8* %4, i64 %7
store i8 %9, i8* %13
%14 = getelementptr inbounds i8, i8* %8, i64 1
%15 = add nuw i64 %7, 1
br label %6
16: ; preds = %6, %10
%17 = phi i8* [ %11, %10 ], [ %8, %6 ]
%18 = call signext i16 @atoi(i8* %17)
%19 = load i32, i32* @AF_INET
%20 = call i32 @htons(i16 signext %18)
%21 = call i32 @inet_addr(i8* %4)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %4)
%23 = sext i16 %18 to i32
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = zext i32 %20 to i64
%26 = shl nuw i64 %25, 32
%27 = zext i32 %21 to i64
%28 = or i64 %26, %27
%29 = insertvalue { i64, i32 } poison, i64 %28, 0
%30 = insertvalue { i64, i32 } %29, i32 %19, 1
ret { i64, i32 } %30
}