#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*/ free(char *);
int hex_to_dec(char *);
char *strndup(char const *, int);
void mac_to_bytes(const char *device_mac, char mac_bytes[]) {
  char to_limit, i;
  int mac_byte;
  char *chunk;
  for (i = 0; i < 6; i++) {
    to_limit = (i * 2) + i;
    chunk = strndup(device_mac + to_limit, 2);
    mac_byte = hex_to_dec(chunk);
    mac_bytes[i] = mac_byte;
    free(chunk);
  }
}


x86 assembly (clang, -O0):
<mac_to_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x12(%rbp)
movsbl -0x12(%rbp),%eax
cmp    $0x6,%eax
jge    11af <mac_to_bytes+0x7f>
movsbl -0x12(%rbp),%eax
shl    $0x1,%eax
movsbl -0x12(%rbp),%ecx
add    %ecx,%eax
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
movsbl -0x11(%rbp),%eax
cltq
add    %rax,%rdi
mov    $0x2,%esi
call   1040 <strndup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <hex_to_dec@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movsbq -0x12(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x12(%rbp),%al
add    $0x1,%al
mov    %al,-0x12(%rbp)
jmp    1144 <mac_to_bytes+0x14>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mac_to_bytes>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2,%esi
call   1040 <strndup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <hex_to_dec@plt>
mov    %al,(%r14)
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0x3(%r15),%rdi
mov    $0x2,%esi
call   1040 <strndup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <hex_to_dec@plt>
mov    %al,0x1(%r14)
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0x6(%r15),%rdi
mov    $0x2,%esi
call   1040 <strndup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <hex_to_dec@plt>
mov    %al,0x2(%r14)
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0x9(%r15),%rdi
mov    $0x2,%esi
call   1040 <strndup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <hex_to_dec@plt>
mov    %al,0x3(%r14)
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xc(%r15),%rdi
mov    $0x2,%esi
call   1040 <strndup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <hex_to_dec@plt>
mov    %al,0x4(%r14)
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0xf,%r15
mov    %r15,%rdi
mov    $0x2,%esi
call   1040 <strndup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <hex_to_dec@plt>
mov    %al,0x5(%r14)
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

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

LLVM IR (-O2):
define void @mac_to_bytes(i8* nocapture %0, i8* nocapture writeonly %1) {
%3 = tail call i8* @strndup(i8* %0, i32 2)
%4 = tail call i32 @hex_to_dec(i8* %3)
%5 = trunc i32 %4 to i8
store i8 %5, i8* %1
%6 = tail call i32 @free(i8* %3)
%7 = getelementptr inbounds i8, i8* %0, i64 3
%8 = tail call i8* @strndup(i8* %7, i32 2)
%9 = tail call i32 @hex_to_dec(i8* %8)
%10 = trunc i32 %9 to i8
%11 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %10, i8* %11
%12 = tail call i32 @free(i8* %8)
%13 = getelementptr inbounds i8, i8* %0, i64 6
%14 = tail call i8* @strndup(i8* %13, i32 2)
%15 = tail call i32 @hex_to_dec(i8* %14)
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %16, i8* %17
%18 = tail call i32 @free(i8* %14)
%19 = getelementptr inbounds i8, i8* %0, i64 9
%20 = tail call i8* @strndup(i8* %19, i32 2)
%21 = tail call i32 @hex_to_dec(i8* %20)
%22 = trunc i32 %21 to i8
%23 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %22, i8* %23
%24 = tail call i32 @free(i8* %20)
%25 = getelementptr inbounds i8, i8* %0, i64 12
%26 = tail call i8* @strndup(i8* %25, i32 2)
%27 = tail call i32 @hex_to_dec(i8* %26)
%28 = trunc i32 %27 to i8
%29 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %28, i8* %29
%30 = tail call i32 @free(i8* %26)
%31 = getelementptr inbounds i8, i8* %0, i64 15
%32 = tail call i8* @strndup(i8* %31, i32 2)
%33 = tail call i32 @hex_to_dec(i8* %32)
%34 = trunc i32 %33 to i8
%35 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %34, i8* %35
%36 = tail call i32 @free(i8* %32)
ret void
}