#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 getnext(char *, char, char *);
unsigned char strtol(char *, int /*<<< orphan*/ *, int);
int str_to_mac(unsigned char *mac, char *str) {
  int len;
  char *ptr = str;
  char buf[128];
  int i;
  for (i = 0; i < 5; i++) {
    if ((len = getnext(ptr, ':', buf)) == -1) {
      return 1;
    }
    mac[i] = strtol(buf, NULL, 16);
    ptr += len;
  }
  mac[5] = strtol(ptr, NULL, 16);
  return 0;
}


x86 assembly (clang, -O0):
<str_to_mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0xb4(%rbp)
cmpl   $0x5,-0xb4(%rbp)
jge    11c9 <str_to_mac+0xa9>
mov    -0x28(%rbp),%rdi
lea    -0xb0(%rbp),%rdx
mov    $0x3a,%esi
call   1040 <getnext@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    117f <str_to_mac+0x5f>
movl   $0x1,-0x4(%rbp)
jmp    11eb <str_to_mac+0xcb>
lea    -0xb0(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0xb4(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    1145 <str_to_mac+0x25>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x5(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_mac>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%rdx
mov    %rsi,%rdi
mov    $0x3a,%esi
call   1040 <getnext@plt>
mov    $0x1,%r15d
cmp    $0xffffffff,%eax
je     1258 <str_to_mac+0x138>
mov    %eax,%ebp
mov    %rsp,%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %al,(%r14)
movslq %ebp,%rax
add    %rax,%rbx
mov    %rbx,%rdi
mov    $0x3a,%esi
mov    %r12,%rdx
call   1040 <getnext@plt>
cmp    $0xffffffff,%eax
je     1258 <str_to_mac+0x138>
mov    %eax,%ebp
mov    %rsp,%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %al,0x1(%r14)
movslq %ebp,%rax
add    %rax,%rbx
mov    %rbx,%rdi
mov    $0x3a,%esi
mov    %r12,%rdx
call   1040 <getnext@plt>
cmp    $0xffffffff,%eax
je     1258 <str_to_mac+0x138>
mov    %eax,%ebp
mov    %rsp,%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %al,0x2(%r14)
movslq %ebp,%rax
add    %rax,%rbx
mov    %rbx,%rdi
mov    $0x3a,%esi
mov    %r12,%rdx
call   1040 <getnext@plt>
cmp    $0xffffffff,%eax
je     1258 <str_to_mac+0x138>
mov    %eax,%ebp
mov    %rsp,%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %al,0x3(%r14)
movslq %ebp,%rax
add    %rax,%rbx
mov    %rbx,%rdi
mov    $0x3a,%esi
mov    %r12,%rdx
call   1040 <getnext@plt>
cmp    $0xffffffff,%eax
je     1258 <str_to_mac+0x138>
mov    %eax,%ebp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %al,0x4(%r14)
movslq %ebp,%rax
add    %rax,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %al,0x5(%r14)
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @str_to_mac(i8* nocapture writeonly %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = call i32 @getnext(i8* %1, i8 signext 58, i8* %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %41, label %7
7: ; preds = %2
%8 = call zeroext i8 @strtol(i8* nocapture %4, i32* null, i32 16)
store i8 %8, i8* %0
%9 = sext i32 %5 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = call i32 @getnext(i8* %10, i8 signext 58, i8* %4)
%12 = icmp eq i32 %11, -1
br i1 %12, label %41, label %13
13: ; preds = %7
%14 = call zeroext i8 @strtol(i8* nocapture %4, i32* null, i32 16)
%15 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %14, i8* %15
%16 = sext i32 %11 to i64
%17 = getelementptr inbounds i8, i8* %10, i64 %16
%18 = call i32 @getnext(i8* %17, i8 signext 58, i8* %4)
%19 = icmp eq i32 %18, -1
br i1 %19, label %41, label %20
20: ; preds = %13
%21 = call zeroext i8 @strtol(i8* nocapture %4, i32* null, i32 16)
%22 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %21, i8* %22
%23 = sext i32 %18 to i64
%24 = getelementptr inbounds i8, i8* %17, i64 %23
%25 = call i32 @getnext(i8* %24, i8 signext 58, i8* %4)
%26 = icmp eq i32 %25, -1
br i1 %26, label %41, label %27
27: ; preds = %20
%28 = call zeroext i8 @strtol(i8* nocapture %4, i32* null, i32 16)
%29 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %28, i8* %29
%30 = sext i32 %25 to i64
%31 = getelementptr inbounds i8, i8* %24, i64 %30
%32 = call i32 @getnext(i8* %31, i8 signext 58, i8* %4)
%33 = icmp eq i32 %32, -1
br i1 %33, label %41, label %34
34: ; preds = %27
%35 = call zeroext i8 @strtol(i8* nocapture %4, i32* null, i32 16)
%36 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %35, i8* %36
%37 = sext i32 %32 to i64
%38 = getelementptr inbounds i8, i8* %31, i64 %37
%39 = call zeroext i8 @strtol(i8* nocapture %38, i32* null, i32 16)
%40 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %39, i8* %40
br label %41
41: ; preds = %2, %7, %13, %20, %27, %34
%42 = phi i32 [ 0, %34 ], [ 1, %27 ], [ 1, %20 ], [ 1, %13 ], [ 1, %7 ], [ 1, %2 ]
ret i32 %42
}