#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*/ sscanf(char const *, char *, int *);
char *strchr(char const *, char);
void convert_string_to_mac(const char *string, unsigned char *mac) {
  int c;
  for (c = 0; c < 6 && string; c++) {
    int x = 0;
    if (string)
      sscanf(string, "%x", &x);
    mac[c] = x;
    string = strchr(string, ':');
    if (string)
      string++;
  }
}


x86 assembly (clang, -O0):
<convert_string_to_mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x6,-0x14(%rbp)
mov    %al,-0x19(%rbp)
jge    1151 <convert_string_to_mac+0x31>
cmpq   $0x0,-0x8(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1161 <convert_string_to_mac+0x41>
jmp    11d3 <convert_string_to_mac+0xb3>
movl   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1187 <convert_string_to_mac+0x67>
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <sscanf@plt>
mov    -0x18(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11c0 <convert_string_to_mac+0xa0>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11c5 <convert_string_to_mac+0xa5>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1137 <convert_string_to_mac+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_string_to_mac>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     1196 <convert_string_to_mac+0x76>
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %r13d,%r13d
lea    0xebe(%rip),%r15
lea    0xc(%rsp),%r12
nopw   0x0(%rax,%rax,1)
movl   $0x0,0xc(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <sscanf@plt>
movzbl 0xc(%rsp),%eax
mov    %al,(%r14,%r13,1)
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %rax,%rbx
cmp    $0x4,%r13
ja     1196 <convert_string_to_mac+0x76>
add    $0x1,%r13
test   %rax,%rax
jne    1150 <convert_string_to_mac+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%x\00"
define void @convert_string_to_mac(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
br label %7
7: ; preds = %36, %2
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 6
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i8*, i8** %3
%12 = icmp ne i8* %11, null
br label %13
13: ; preds = %10, %7
%14 = phi i1 [ false, %7 ], [ %12, %10 ]
br i1 %14, label %15, label %39
15: ; preds = %13
store i32 0, i32* %6
%16 = load i8*, i8** %3
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i8*, i8** %3
%20 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
br label %21
21: ; preds = %18, %15
%22 = load i32, i32* %6
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 %23, i8* %27
%28 = load i8*, i8** %3
%29 = call i8* @strchr(i8* %28, i8 signext 58)
store i8* %29, i8** %3
%30 = load i8*, i8** %3
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %35
32: ; preds = %21
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %3
br label %35
35: ; preds = %32, %21
br label %36
36: ; preds = %35
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %7
39: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%x\00"
define void @convert_string_to_mac(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = icmp eq i8* %0, null
br i1 %4, label %22, label %5
5: ; preds = %2
%6 = bitcast i32* %3 to i8*
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %18, %7 ]
%9 = phi i8* [ %0, %5 ], [ %17, %7 ]
store i32 0, i32* %3
%10 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%11 = load i32, i32* %3
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds i8, i8* %1, i64 %8
store i8 %12, i8* %13
%14 = call i8* @strchr(i8* %9, i8 signext 58)
%15 = icmp eq i8* %14, null
%16 = getelementptr inbounds i8, i8* %14, i64 1
%17 = select i1 %15, i8* null, i8* %16
%18 = add nuw nsw i64 %8, 1
%19 = icmp ult i64 %8, 5
%20 = xor i1 %15, true
%21 = select i1 %19, i1 %20, i1 false
br i1 %21, label %7, label %22
22: ; preds = %7, %2
ret void
}