#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 convertStrToMac(const char *macStr, char separator,
                     unsigned char *macByteArr, int maxBytes, int base) {
  int i;
  for (i = 0; i < maxBytes; i++) {
    macByteArr[i] = strtoul(macStr, NULL, base);
    macStr = strchr(macStr, separator);
    if (macStr == NULL || *macStr == '\0') {
      break;
    }
    macStr++;
  }
}


x86 assembly (clang, -O0):
<convertStrToMac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b8 <convertStrToMac+0x98>
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)
mov    -0x8(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1199 <convertStrToMac+0x79>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    119e <convertStrToMac+0x7e>
jmp    11b8 <convertStrToMac+0x98>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1144 <convertStrToMac+0x24>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertStrToMac>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %ecx,%ecx
jle    118a <convertStrToMac+0x6a>
mov    %r8d,%r14d
mov    %rdx,%r15
mov    %rdi,%rbp
mov    %ecx,%r12d
mov    $0x1,%ebx
movsbl %sil,%r13d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1040 <strtoul@plt>
mov    %al,-0x1(%r15,%rbx,1)
mov    %rbp,%rdi
mov    %r13d,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     118a <convertStrToMac+0x6a>
mov    %rax,%rbp
cmpb   $0x0,(%rax)
je     118a <convertStrToMac+0x6a>
add    $0x1,%rbp
lea    0x1(%rbx),%rax
cmp    %r12,%rbx
mov    %rax,%rbx
jb     1150 <convertStrToMac+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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