#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 */
char *strchr(char const *, char);
unsigned char strtoul(char const *, int /*<<< orphan*/ *, int);
void convertStrToIP(const char *ipStr, char sep1, char sep2,
                    unsigned char *ipByteArr, int maxBytes, int base) {
  int i;
  for (i = 0; i < maxBytes; i++) {
    ipByteArr[i] = strtoul(ipStr, NULL, base);
    if ((sep2 != '\0') && (i == 3)) {
      ipStr = strchr(ipStr, sep2);
    } else {
      ipStr = strchr(ipStr, sep1);
    }
    if (ipStr == NULL || *ipStr == '\0') {
      break;
    }
    ipStr++;
  }
}


x86 assembly (clang, -O0):
<convertStrToIP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %sil,%dl
mov    %rdi,-0x8(%rbp)
mov    %dl,-0x9(%rbp)
mov    %al,-0xa(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11eb <convertStrToIP+0xcb>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <strtoul@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movsbl -0xa(%rbp),%eax
cmp    $0x0,%eax
je     11a0 <convertStrToIP+0x80>
cmpl   $0x3,-0x24(%rbp)
jne    11a0 <convertStrToIP+0x80>
mov    -0x8(%rbp),%rdi
movsbl -0xa(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x8(%rbp)
jmp    11b1 <convertStrToIP+0x91>
mov    -0x8(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11cc <convertStrToIP+0xac>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d1 <convertStrToIP+0xb1>
jmp    11eb <convertStrToIP+0xcb>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114a <convertStrToIP+0x2a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertStrToIP>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,0x4(%rsp)
test   %r8d,%r8d
jle    119d <convertStrToIP+0x7d>
mov    %rcx,%r15
mov    %rdi,%rbp
mov    %r8d,%r12d
mov    $0x1,%ebx
movzbl %dl,%r13d
movzbl %sil,%r14d
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
xor    %esi,%esi
mov    0x4(%rsp),%edx
call   1040 <strtoul@plt>
cmp    $0x4,%rbx
mov    %r14d,%ecx
cmove  %r13d,%ecx
test   %r13b,%r13b
mov    %al,-0x1(%r15,%rbx,1)
cmove  %r14d,%ecx
movsbl %cl,%esi
mov    %rbp,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     119d <convertStrToIP+0x7d>
mov    %rax,%rbp
cmpb   $0x0,(%rax)
je     119d <convertStrToIP+0x7d>
add    $0x1,%rbp
lea    0x1(%rbx),%rax
cmp    %r12,%rbx
mov    %rax,%rbx
jb     1150 <convertStrToIP+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @convertStrToIP(i8* %0, i8 signext %1, i8 signext %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %7
store i8 %1, i8* %8
store i8 %2, i8* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i32 %5, i32* %12
store i32 0, i32* %13
br label %14
14: ; preds = %52, %6
%15 = load i32, i32* %13
%16 = load i32, i32* %11
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %55
18: ; preds = %14
%19 = load i8*, i8** %7
%20 = load i32, i32* %12
%21 = call zeroext i8 @strtoul(i8* %19, i32* null, i32 %20)
%22 = load i8*, i8** %10
%23 = load i32, i32* %13
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 %21, i8* %25
%26 = load i8, i8* %9
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %18
%30 = load i32, i32* %13
%31 = icmp eq i32 %30, 3
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i8*, i8** %7
%34 = load i8, i8* %9
%35 = call i8* @strchr(i8* %33, i8 signext %34)
store i8* %35, i8** %7
br label %40
36: ; preds = %29, %18
%37 = load i8*, i8** %7
%38 = load i8, i8* %8
%39 = call i8* @strchr(i8* %37, i8 signext %38)
store i8* %39, i8** %7
br label %40
40: ; preds = %36, %32
%41 = load i8*, i8** %7
%42 = icmp eq i8* %41, null
br i1 %42, label %48, label %43
43: ; preds = %40
%44 = load i8*, i8** %7
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %43, %40
br label %55
49: ; preds = %43
%50 = load i8*, i8** %7
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %7
br label %52
52: ; preds = %49
%53 = load i32, i32* %13
%54 = add nsw i32 %53, 1
store i32 %54, i32* %13
br label %14
55: ; preds = %48, %14
ret void
}

LLVM IR (-O2):
define void @convertStrToIP(i8* %0, i8 signext %1, i8 signext %2, i8* nocapture writeonly %3, i32 %4, i32 %5) {
%7 = icmp sgt i32 %4, 0
br i1 %7, label %8, label %28
8: ; preds = %6
%9 = icmp ne i8 %2, 0
%10 = zext i32 %4 to i64
br label %11
11: ; preds = %21, %8
%12 = phi i64 [ %25, %21 ], [ 0, %8 ]
%13 = phi i8* [ %24, %21 ], [ %0, %8 ]
%14 = tail call zeroext i8 @strtoul(i8* nocapture %13, i32* null, i32 %5)
%15 = getelementptr inbounds i8, i8* %3, i64 %12
store i8 %14, i8* %15
%16 = icmp eq i64 %12, 3
%17 = select i1 %9, i1 %16, i1 false
%18 = select i1 %17, i8 %2, i8 %1
%19 = tail call i8* @strchr(i8* dereferenceable(1) %13, i8 signext %18)
%20 = icmp eq i8* %19, null
br i1 %20, label %28, label %21
21: ; preds = %11
%22 = load i8, i8* %19
%23 = icmp ne i8 %22, 0
%24 = getelementptr inbounds i8, i8* %19, i64 1
%25 = add nuw nsw i64 %12, 1
%26 = icmp ult i64 %25, %10
%27 = select i1 %23, i1 %26, i1 false
br i1 %27, label %11, label %28
28: ; preds = %21, %11, %6
ret void
}