#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 */
typedef int uint8_t;

/* Variables and functions */
scalar_t__ malloc(int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
scalar_t__ strtok(char *, char *);
uint8_t *parsemac(char *str) {
  uint8_t *ret = (uint8_t *)malloc(6 * sizeof(char));
  char *num = (char *)strtok(str, ":");
  int index = 0;
  while (num != NULL) {
    int i;
    sscanf(num, "%x", &i);
    ret[index++] = i;
    num = (char *)strtok(NULL, ":");
  }
  return ret;
}


x86 assembly (clang, -O0):
<parsemac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x6,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeab(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b5 <parsemac+0x85>
mov    -0x18(%rbp),%rdi
lea    0xe87(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <sscanf@plt>
mov    -0x20(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe59(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    1165 <parsemac+0x35>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsemac>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    $0x6,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     11a7 <parsemac+0x77>
lea    0xe9a(%rip),%r15
lea    0xc(%rsp),%r12
lea    0xe8c(%rip),%r13
mov    %r14,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <sscanf@plt>
mov    0xc(%rsp),%eax
mov    %eax,(%rbx)
xor    %edi,%edi
mov    %r13,%rsi
call   1050 <strtok@plt>
add    $0x4,%rbx
test   %rax,%rax
jne    1180 <parsemac+0x50>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c":\00"
@.str.1 = [3 x i8] c"%x\00"
define i32* @parsemac(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = call i64 @malloc(i32 6)
%8 = inttoptr i64 %7 to i32*
store i32* %8, i32** %3
%9 = load i8*, i8** %2
%10 = call i64 @strtok(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %4
store i32 0, i32* %5
br label %12
12: ; preds = %15, %1
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%18 = load i32, i32* %6
%19 = load i32*, i32** %3
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds i32, i32* %19, i64 %22
store i32 %18, i32* %23
%24 = call i64 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %4
br label %12
26: ; preds = %12
%27 = load i32*, i32** %3
ret i32* %27
}

LLVM IR (-O2):
@.str = [2 x i8] c":\00"
@.str.1 = [3 x i8] c"%x\00"
define i32* @parsemac(i8* %0) {
%2 = alloca i32
%3 = tail call i64 @malloc(i32 6)
%4 = inttoptr i64 %3 to i32*
%5 = tail call i64 @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %1
%8 = bitcast i32* %2 to i8*
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %15, %9 ]
%11 = phi i64 [ %5, %7 ], [ %17, %9 ]
%12 = inttoptr i64 %11 to i8*
%13 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%14 = load i32, i32* %2
%15 = add nuw i64 %10, 1
%16 = getelementptr inbounds i32, i32* %4, i64 %10
store i32 %14, i32* %16
%17 = call i64 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %9
19: ; preds = %9, %1
ret i32* %4
}