#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 in_addr {
  long s_addr;
};

/* Variables and functions */
long INADDR_ANY;
int /*<<< orphan*/ LOG_ERR;
short atoi(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ inet_aton(char *, struct in_addr *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int parseIp(char *ipstring, long *addr, short *port) {
  int i = 0;
  struct in_addr inaddr;
  char *addrPtr;
  *port = 0;
  *addr = INADDR_ANY;
  addrPtr = ipstring;
  while ((ipstring[i] != '\0') && (ipstring[i] != ':')) {
    i++;
  }
  if (ipstring[i] = ':') {
    ipstring[i] = '\0';
    i++;
    ipstring += i;
    *port = atoi(ipstring);
  }
  if (addrPtr[0] != '0') {
    if (inet_aton(addrPtr, &inaddr) == 0) {
      syslog(LOG_ERR, "Parse error - exiting");
      printf("Parse error - exiting\n");
      exit(-1);
    }
    *addr = inaddr.s_addr;
  }
}


x86 assembly (clang, -O0):
<parseIp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rax
movw   $0x0,(%rax)
mov    0x2e6d(%rip),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
je     11bc <parseIp+0x6c>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11cc <parseIp+0x7c>
jmp    11da <parseIp+0x8a>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118d <parseIp+0x3d>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x3a,(%rax,%rcx,1)
mov    $0x1,%al
test   $0x1,%al
jne    11f5 <parseIp+0xa5>
jmp    122e <parseIp+0xde>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <atoi@plt>
mov    %ax,%cx
mov    -0x20(%rbp),%rax
mov    %cx,(%rax)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
je     128b <parseIp+0x13b>
mov    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <inet_aton@plt>
cmp    $0x0,%rax
jne    1280 <parseIp+0x130>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
lea    0xd9b(%rip),%rsi
call   1050 <syslog@plt>
lea    0xda5(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseIp>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
movw   $0x0,(%rdx)
mov    0x2e7a(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rsi)
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
movzbl (%rbx,%rdi,1),%eax
test   %al,%al
je     1192 <parseIp+0x42>
cmp    $0x3a,%al
je     1192 <parseIp+0x42>
add    $0x1,%rdi
jmp    1180 <parseIp+0x30>
mov    %edi,%eax
movb   $0x0,(%rbx,%rax,1)
add    $0x1,%edi
add    %rbx,%rdi
call   1060 <atoi@plt>
mov    %ax,(%r15)
cmpb   $0x30,(%rbx)
je     11c6 <parseIp+0x76>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <inet_aton@plt>
test   %rax,%rax
je     11d0 <parseIp+0x80>
mov    0x8(%rsp),%rax
mov    %rax,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rbx
mov    %rbx,%rsi
call   1050 <syslog@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.in_addr = type { i64 }
@INADDR_ANY = global i64 0
@LOG_ERR = global i32 0
@.str = [22 x i8] c"Parse error - exiting\00"
@.str.1 = [23 x i8] c"Parse error - exiting\0A\00"
define i32 @parseIp(i8* %0, i64* %1, i16* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i16*
%8 = alloca i32
%9 = alloca %struct.in_addr
%10 = alloca i8*
store i8* %0, i8** %5
store i64* %1, i64** %6
store i16* %2, i16** %7
store i32 0, i32* %8
%11 = load i16*, i16** %7
store i16 0, i16* %11
%12 = load i64, i64* @INADDR_ANY
%13 = load i64*, i64** %6
store i64 %12, i64* %13
%14 = load i8*, i8** %5
store i8* %14, i8** %10
br label %15
15: ; preds = %33, %3
%16 = load i8*, i8** %5
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %15
%24 = load i8*, i8** %5
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 58
br label %31
31: ; preds = %23, %15
%32 = phi i1 [ false, %15 ], [ %30, %23 ]
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %15
36: ; preds = %31
%37 = load i8*, i8** %5
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 58, i8* %40
br i1 true, label %41, label %55
41: ; preds = %36
%42 = load i8*, i8** %5
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 0, i8* %45
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
%48 = load i32, i32* %8
%49 = load i8*, i8** %5
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds i8, i8* %49, i64 %50
store i8* %51, i8** %5
%52 = load i8*, i8** %5
%53 = call signext i16 @atoi(i8* %52)
%54 = load i16*, i16** %7
store i16 %53, i16* %54
br label %55
55: ; preds = %41, %36
%56 = load i8*, i8** %10
%57 = getelementptr inbounds i8, i8* %56, i64 0
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp ne i32 %59, 48
br i1 %60, label %61, label %74
61: ; preds = %55
%62 = load i8*, i8** %10
%63 = call i64 @inet_aton(i8* %62, %struct.in_addr* %9)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %61
%66 = load i32, i32* @LOG_ERR
%67 = call i32 @syslog(i32 %66, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%68 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%69 = call i32 @exit(i32 -1)
unreachable
70: ; preds = %61
%71 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
%72 = load i64, i64* %71
%73 = load i64*, i64** %6
store i64 %72, i64* %73
br label %74
74: ; preds = %70, %55
%75 = load i32, i32* %4
ret i32 %75
}

LLVM IR (-O2):
%struct.in_addr = type { i64 }
@INADDR_ANY = global i64 0
@LOG_ERR = global i32 0
@str = [22 x i8] c"Parse error - exiting\00"
define i32 @parseIp(i8* %0, i64* nocapture writeonly %1, i16* nocapture writeonly %2) {
%4 = alloca %struct.in_addr
%5 = bitcast %struct.in_addr* %4 to i8*
store i16 0, i16* %2
%6 = load i64, i64* @INADDR_ANY
store i64 %6, i64* %1
br label %7
7: ; preds = %11, %3
%8 = phi i64 [ %12, %11 ], [ 0, %3 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
switch i8 %10, label %11 [
i8 0, label %13
i8 58, label %13
]
11: ; preds = %7
%12 = add nuw i64 %8, 1
br label %7
13: ; preds = %7, %7
%14 = and i64 %8, 4294967295
%15 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 0, i8* %15
%16 = add i64 %8, 1
%17 = and i64 %16, 4294967295
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = tail call signext i16 @atoi(i8* %18)
store i16 %19, i16* %2
%20 = load i8, i8* %0
%21 = icmp eq i8 %20, 48
br i1 %21, label %33, label %22
22: ; preds = %13
%23 = call i64 @inet_aton(i8* %0, %struct.in_addr* %4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i32, i32* @LOG_ERR
%27 = call i32 @syslog(i32 %26, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %22
%31 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i64 0, i32 0
%32 = load i64, i64* %31
store i64 %32, i64* %1
br label %33
33: ; preds = %30, %13
ret i32 undef
}