#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 */
int /*<<< orphan*/ LOG(char *, ...);
long strtol(char *, char **, int);
int parseLine(char *line, unsigned short *dstPort, unsigned long *srcAddy) {
  long int temp;
  char *ptr = line;
  int x;
  int i;
  x = 0;
  i = 0;
  while (line[i] != '\0') {
    if (line[i] == ':') {
      x++;
    }
    if (x == 2) {
      break;
    }
    i++;
  }
  if (x != 2) {
    LOG("Never found 3rd colon\n");
    return -1;
  }
  i++;
  temp = strtol(&line[++i], &ptr, 16);
  if (ptr == &line[i]) {
    LOG("couldn't get string out of %s\n", &line[i]);
    return -1;
  }
  *dstPort = (unsigned short)temp;
  line = &ptr[1];
  temp = strtol(line, &ptr, 16);
  if (ptr == &line[i]) {
    LOG("couldn't get string out of %s\n", &line[i]);
    return -1;
  }
  *srcAddy = (unsigned long)temp;
  return 0;
}


x86 assembly (clang, -O0):
<parseLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     119a <parseLine+0x7a>
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    117d <parseLine+0x5d>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x2,-0x34(%rbp)
jne    118c <parseLine+0x6c>
jmp    119a <parseLine+0x7a>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    114a <parseLine+0x2a>
cmpl   $0x2,-0x34(%rbp)
je     11be <parseLine+0x9e>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <LOG@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a7 <parseLine+0x187>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
cltq
add    %rax,%rdi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x38(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jne    1228 <parseLine+0x108>
mov    -0x10(%rbp),%rsi
movslq -0x38(%rbp),%rax
add    %rax,%rsi
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1040 <LOG@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a7 <parseLine+0x187>
mov    -0x28(%rbp),%rax
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x38(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jne    1295 <parseLine+0x175>
mov    -0x10(%rbp),%rsi
movslq -0x38(%rbp),%rax
add    %rax,%rsi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1040 <LOG@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a7 <parseLine+0x187>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseLine>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rdi,0x8(%rsp)
xor    %ecx,%ecx
mov    $0x2,%eax
jmp    115c <parseLine+0x3c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ecx
cmp    $0x2,%ecx
je     117a <parseLine+0x5a>
add    $0x1,%rax
movzbl -0x2(%rbx,%rax,1),%edx
cmp    $0x3a,%dl
je     1150 <parseLine+0x30>
test   %dl,%dl
jne    1158 <parseLine+0x38>
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1040 <LOG@plt>
jmp    11e6 <parseLine+0xc6>
mov    %eax,%r12d
add    %r12,%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    0x8(%rsp),%r13
cmp    %rbx,%r13
je     11cc <parseLine+0xac>
mov    %ax,(%r15)
lea    0x1(%r13),%rdi
lea    0x8(%rsp),%rsi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    0x8(%rsp),%rsi
lea    (%r12,%r13,1),%rcx
add    $0x1,%rcx
cmp    %rcx,%rsi
je     11d8 <parseLine+0xb8>
mov    %rax,(%r14)
xor    %eax,%eax
jmp    11eb <parseLine+0xcb>
lea    0xe44(%rip),%rdi
mov    %rbx,%rsi
jmp    11df <parseLine+0xbf>
lea    0xe38(%rip),%rdi
xor    %eax,%eax
call   1040 <LOG@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Never found 3rd colon\0A\00"
@.str.1 = [31 x i8] c"couldn't get string out of %s\0A\00"
define i32 @parseLine(i8* %0, i16* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i16*
%7 = alloca i64*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i16* %1, i16** %6
store i64* %2, i64** %7
%12 = load i8*, i8** %5
store i8* %12, i8** %9
store i32 0, i32* %10
store i32 0, i32* %11
br label %13
13: ; preds = %36, %3
%14 = load i8*, i8** %5
%15 = load i32, i32* %11
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %39
21: ; preds = %13
%22 = load i8*, i8** %5
%23 = load i32, i32* %11
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 58
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = load i32, i32* %10
%31 = add nsw i32 %30, 1
store i32 %31, i32* %10
br label %32
32: ; preds = %29, %21
%33 = load i32, i32* %10
%34 = icmp eq i32 %33, 2
br i1 %34, label %35, label %36
35: ; preds = %32
br label %39
36: ; preds = %32
%37 = load i32, i32* %11
%38 = add nsw i32 %37, 1
store i32 %38, i32* %11
br label %13
39: ; preds = %35, %13
%40 = load i32, i32* %10
%41 = icmp ne i32 %40, 2
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 (i8*, ...) @LOG(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %88
44: ; preds = %39
%45 = load i32, i32* %11
%46 = add nsw i32 %45, 1
store i32 %46, i32* %11
%47 = load i8*, i8** %5
%48 = load i32, i32* %11
%49 = add nsw i32 %48, 1
store i32 %49, i32* %11
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
%52 = call i64 @strtol(i8* %51, i8** %9, i32 16)
store i64 %52, i64* %8
%53 = load i8*, i8** %9
%54 = load i8*, i8** %5
%55 = load i32, i32* %11
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = icmp eq i8* %53, %57
br i1 %58, label %59, label %65
59: ; preds = %44
%60 = load i8*, i8** %5
%61 = load i32, i32* %11
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = call i32 (i8*, ...) @LOG(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %63)
store i32 -1, i32* %4
br label %88
65: ; preds = %44
%66 = load i64, i64* %8
%67 = trunc i64 %66 to i16
%68 = load i16*, i16** %6
store i16 %67, i16* %68
%69 = load i8*, i8** %9
%70 = getelementptr inbounds i8, i8* %69, i64 1
store i8* %70, i8** %5
%71 = load i8*, i8** %5
%72 = call i64 @strtol(i8* %71, i8** %9, i32 16)
store i64 %72, i64* %8
%73 = load i8*, i8** %9
%74 = load i8*, i8** %5
%75 = load i32, i32* %11
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %74, i64 %76
%78 = icmp eq i8* %73, %77
br i1 %78, label %79, label %85
79: ; preds = %65
%80 = load i8*, i8** %5
%81 = load i32, i32* %11
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
%84 = call i32 (i8*, ...) @LOG(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %83)
store i32 -1, i32* %4
br label %88
85: ; preds = %65
%86 = load i64, i64* %8
%87 = load i64*, i64** %7
store i64 %86, i64* %87
store i32 0, i32* %4
br label %88
88: ; preds = %85, %79, %59, %42
%89 = load i32, i32* %4
ret i32 %89
}

LLVM IR (-O2):
@.str = [23 x i8] c"Never found 3rd colon\0A\00"
@.str.1 = [31 x i8] c"couldn't get string out of %s\0A\00"
define i32 @parseLine(i8* %0, i16* nocapture writeonly %1, i64* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* %0, i8** %4
br label %6
6: ; preds = %14, %3
%7 = phi i64 [ %16, %14 ], [ 0, %3 ]
%8 = phi i32 [ %15, %14 ], [ 0, %3 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
switch i8 %10, label %14 [
i8 0, label %17
i8 58, label %11
]
11: ; preds = %6
%12 = add nsw i32 %8, 1
%13 = icmp eq i32 %12, 2
br i1 %13, label %19, label %14
14: ; preds = %6, %11
%15 = phi i32 [ %12, %11 ], [ %8, %6 ]
%16 = add nuw i64 %7, 1
br label %6
17: ; preds = %6
%18 = tail call i32 (i8*, ...) @LOG(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %38
19: ; preds = %11
%20 = add i64 %7, 2
%21 = and i64 %20, 4294967295
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = call i64 @strtol(i8* %22, i8** %4, i32 16)
%24 = load i8*, i8** %4
%25 = icmp eq i8* %24, %22
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = tail call i32 (i8*, ...) @LOG(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %38
28: ; preds = %19
%29 = trunc i64 %23 to i16
store i16 %29, i16* %1
%30 = getelementptr inbounds i8, i8* %24, i64 1
%31 = call i64 @strtol(i8* %30, i8** %4, i32 16)
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %30, i64 %21
%34 = icmp eq i8* %32, %33
br i1 %34, label %35, label %37
35: ; preds = %28
%36 = tail call i32 (i8*, ...) @LOG(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %32)
br label %38
37: ; preds = %28
store i64 %31, i64* %2
br label %38
38: ; preds = %37, %35, %26, %17
%39 = phi i32 [ -1, %17 ], [ -1, %26 ], [ -1, %35 ], [ 0, %37 ]
ret i32 %39
}