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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int strlen(char *);
int /*<<< orphan*/ strtoul(char *, int /*<<< orphan*/ *, int);
uint8_t *asciitomac(char *macstr) {
  int i;
  char bytebuf[3];
  uint8_t *mac;
  char *endptr;
  if (strlen(macstr) < 12) {
    return (NULL);
  }
  endptr = macstr + strlen(macstr);
  mac = (uint8_t *)malloc(6);
  if (mac == NULL) {
    perror("can't allocate memory");
    exit(1);
  }
  for (i = 0; i < 6; i++) {
    bytebuf[0] = *macstr++;
    bytebuf[1] = *macstr++;
    bytebuf[2] = 0x00;
    if (macstr[0] == ':') {
      *macstr++;
    }
    if (macstr > endptr)
      return (NULL);
    mac[i] = strtoul(bytebuf, NULL, 16);
  }
  return (mac);
}


x86 assembly (clang, -O0):
<asciitomac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0xc,%eax
jge    117b <asciitomac+0x2b>
movq   $0x0,-0x8(%rbp)
jmp    1274 <asciitomac+0x124>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    $0x6,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cb <asciitomac+0x7b>
lea    0xe44(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x6,-0x14(%rbp)
jge    126c <asciitomac+0x11c>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x17(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x16(%rbp)
movb   $0x0,-0x15(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1224 <asciitomac+0xd4>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    123f <asciitomac+0xef>
movq   $0x0,-0x8(%rbp)
jmp    1274 <asciitomac+0x124>
lea    -0x17(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d2 <asciitomac+0x82>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asciitomac>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0xc,%eax
jge    1170 <asciitomac+0x20>
xor    %r15d,%r15d
jmp    1330 <asciitomac+0x1e0>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    $0x6,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1342 <asciitomac+0x1f2>
mov    %rax,%r14
movslq %ebp,%r13
add    %rbx,%r13
mov    (%rbx),%al
mov    %al,0x5(%rsp)
lea    0x2(%rbx),%rbp
mov    0x1(%rbx),%al
mov    %al,0x6(%rsp)
movb   $0x0,0x7(%rsp)
cmpb   $0x3a,0x2(%rbx)
lea    0x3(%rbx),%rax
cmove  %rax,%rbp
xor    %r15d,%r15d
cmp    %r13,%rbp
ja     1330 <asciitomac+0x1e0>
lea    0x5(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,(%r14)
mov    0x0(%rbp),%al
mov    %al,0x5(%rsp)
lea    0x2(%rbp),%rbx
mov    0x1(%rbp),%al
mov    %al,0x6(%rsp)
movb   $0x0,0x7(%rsp)
cmpb   $0x3a,0x2(%rbp)
lea    0x3(%rbp),%rax
cmove  %rax,%rbx
cmp    %r13,%rbx
ja     1330 <asciitomac+0x1e0>
xor    %r15d,%r15d
lea    0x5(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,0x4(%r14)
mov    (%rbx),%al
mov    %al,0x5(%rsp)
lea    0x2(%rbx),%r12
mov    0x1(%rbx),%al
mov    %al,0x6(%rsp)
movb   $0x0,0x7(%rsp)
cmpb   $0x3a,0x2(%rbx)
lea    0x3(%rbx),%rax
cmove  %rax,%r12
cmp    %r13,%r12
ja     1330 <asciitomac+0x1e0>
xor    %r15d,%r15d
lea    0x5(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,0x8(%r14)
mov    (%r12),%al
mov    %al,0x5(%rsp)
lea    0x2(%r12),%rbx
mov    0x1(%r12),%al
mov    %al,0x6(%rsp)
movb   $0x0,0x7(%rsp)
cmpb   $0x3a,0x2(%r12)
lea    0x3(%r12),%rax
cmove  %rax,%rbx
cmp    %r13,%rbx
ja     1330 <asciitomac+0x1e0>
xor    %r15d,%r15d
lea    0x5(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,0xc(%r14)
mov    (%rbx),%al
mov    %al,0x5(%rsp)
lea    0x2(%rbx),%r12
mov    0x1(%rbx),%al
mov    %al,0x6(%rsp)
movb   $0x0,0x7(%rsp)
cmpb   $0x3a,0x2(%rbx)
lea    0x3(%rbx),%rax
cmove  %rax,%r12
cmp    %r13,%r12
ja     1330 <asciitomac+0x1e0>
xor    %r15d,%r15d
lea    0x5(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,0x10(%r14)
mov    (%r12),%al
mov    %al,0x5(%rsp)
lea    0x2(%r12),%rax
mov    0x1(%r12),%cl
mov    %cl,0x6(%rsp)
movb   $0x0,0x7(%rsp)
cmpb   $0x3a,0x2(%r12)
lea    0x3(%r12),%rcx
cmove  %rcx,%rax
cmp    %r13,%rax
ja     1330 <asciitomac+0x1e0>
lea    0x5(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,0x14(%r14)
mov    %r14,%r15
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcb7(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"can't allocate memory\00"
define i32* @asciitomac(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [3 x i8]
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = icmp slt i32 %9, 12
br i1 %10, label %11, label %12
11: ; preds = %1
store i32* null, i32** %2
br label %65
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
store i8* %17, i8** %7
%18 = call i64 @malloc(i32 6)
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %12
%23 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %12
store i32 0, i32* %4
br label %26
26: ; preds = %60, %25
%27 = load i32, i32* %4
%28 = icmp slt i32 %27, 6
br i1 %28, label %29, label %63
29: ; preds = %26
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %3
%32 = load i8, i8* %30
%33 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 %32, i8* %33
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %3
%36 = load i8, i8* %34
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 %36, i8* %37
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
store i8 0, i8* %38
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 58
br i1 %43, label %44, label %48
44: ; preds = %29
%45 = load i8*, i8** %3
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %3
%47 = load i8, i8* %45
br label %48
48: ; preds = %44, %29
%49 = load i8*, i8** %3
%50 = load i8*, i8** %7
%51 = icmp ugt i8* %49, %50
br i1 %51, label %52, label %53
52: ; preds = %48
store i32* null, i32** %2
br label %65
53: ; preds = %48
%54 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%55 = call i32 @strtoul(i8* %54, i32* null, i32 16)
%56 = load i32*, i32** %6
%57 = load i32, i32* %4
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
store i32 %55, i32* %59
br label %60
60: ; preds = %53
%61 = load i32, i32* %4
%62 = add nsw i32 %61, 1
store i32 %62, i32* %4
br label %26
63: ; preds = %26
%64 = load i32*, i32** %6
store i32* %64, i32** %2
br label %65
65: ; preds = %63, %52, %11
%66 = load i32*, i32** %2
ret i32* %66
}

LLVM IR (-O2):
@.str = [22 x i8] c"can't allocate memory\00"
define i32* @asciitomac(i8* %0) {
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp slt i32 %4, 12
br i1 %5, label %90, label %6
6: ; preds = %1
%7 = tail call i32 @strlen(i8* %0)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = tail call i64 @malloc(i32 6)
%11 = inttoptr i64 %10 to i32*
%12 = icmp eq i64 %10, 0
br i1 %12, label %25, label %13
13: ; preds = %6
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 2
%16 = getelementptr inbounds i8, i8* %0, i64 1
%17 = load i8, i8* %0
store i8 %17, i8* %3
%18 = getelementptr inbounds i8, i8* %0, i64 2
%19 = load i8, i8* %16
store i8 %19, i8* %14
store i8 0, i8* %15
%20 = load i8, i8* %18
%21 = icmp eq i8 %20, 58
%22 = getelementptr inbounds i8, i8* %0, i64 3
%23 = select i1 %21, i8* %22, i8* %18
%24 = icmp ugt i8* %23, %9
br i1 %24, label %90, label %28
25: ; preds = %6
%26 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %13
%29 = call i32 @strtoul(i8* nocapture %3, i32* null, i32 16)
store i32 %29, i32* %11
%30 = getelementptr inbounds i8, i8* %23, i64 1
%31 = load i8, i8* %23
store i8 %31, i8* %3
%32 = getelementptr inbounds i8, i8* %23, i64 2
%33 = load i8, i8* %30
store i8 %33, i8* %14
store i8 0, i8* %15
%34 = load i8, i8* %32
%35 = icmp eq i8 %34, 58
%36 = getelementptr inbounds i8, i8* %23, i64 3
%37 = select i1 %35, i8* %36, i8* %32
%38 = icmp ugt i8* %37, %9
br i1 %38, label %90, label %39
39: ; preds = %28
%40 = call i32 @strtoul(i8* nocapture %3, i32* null, i32 16)
%41 = getelementptr inbounds i32, i32* %11, i64 1
store i32 %40, i32* %41
%42 = getelementptr inbounds i8, i8* %37, i64 1
%43 = load i8, i8* %37
store i8 %43, i8* %3
%44 = getelementptr inbounds i8, i8* %37, i64 2
%45 = load i8, i8* %42
store i8 %45, i8* %14
store i8 0, i8* %15
%46 = load i8, i8* %44
%47 = icmp eq i8 %46, 58
%48 = getelementptr inbounds i8, i8* %37, i64 3
%49 = select i1 %47, i8* %48, i8* %44
%50 = icmp ugt i8* %49, %9
br i1 %50, label %90, label %51
51: ; preds = %39
%52 = call i32 @strtoul(i8* nocapture %3, i32* null, i32 16)
%53 = getelementptr inbounds i32, i32* %11, i64 2
store i32 %52, i32* %53
%54 = getelementptr inbounds i8, i8* %49, i64 1
%55 = load i8, i8* %49
store i8 %55, i8* %3
%56 = getelementptr inbounds i8, i8* %49, i64 2
%57 = load i8, i8* %54
store i8 %57, i8* %14
store i8 0, i8* %15
%58 = load i8, i8* %56
%59 = icmp eq i8 %58, 58
%60 = getelementptr inbounds i8, i8* %49, i64 3
%61 = select i1 %59, i8* %60, i8* %56
%62 = icmp ugt i8* %61, %9
br i1 %62, label %90, label %63
63: ; preds = %51
%64 = call i32 @strtoul(i8* nocapture %3, i32* null, i32 16)
%65 = getelementptr inbounds i32, i32* %11, i64 3
store i32 %64, i32* %65
%66 = getelementptr inbounds i8, i8* %61, i64 1
%67 = load i8, i8* %61
store i8 %67, i8* %3
%68 = getelementptr inbounds i8, i8* %61, i64 2
%69 = load i8, i8* %66
store i8 %69, i8* %14
store i8 0, i8* %15
%70 = load i8, i8* %68
%71 = icmp eq i8 %70, 58
%72 = getelementptr inbounds i8, i8* %61, i64 3
%73 = select i1 %71, i8* %72, i8* %68
%74 = icmp ugt i8* %73, %9
br i1 %74, label %90, label %75
75: ; preds = %63
%76 = call i32 @strtoul(i8* nocapture %3, i32* null, i32 16)
%77 = getelementptr inbounds i32, i32* %11, i64 4
store i32 %76, i32* %77
%78 = getelementptr inbounds i8, i8* %73, i64 1
%79 = load i8, i8* %73
store i8 %79, i8* %3
%80 = getelementptr inbounds i8, i8* %73, i64 2
%81 = load i8, i8* %78
store i8 %81, i8* %14
store i8 0, i8* %15
%82 = load i8, i8* %80
%83 = icmp eq i8 %82, 58
%84 = getelementptr inbounds i8, i8* %73, i64 3
%85 = select i1 %83, i8* %84, i8* %80
%86 = icmp ugt i8* %85, %9
br i1 %86, label %90, label %87
87: ; preds = %75
%88 = call i32 @strtoul(i8* nocapture %3, i32* null, i32 16)
%89 = getelementptr inbounds i32, i32* %11, i64 5
store i32 %88, i32* %89
br label %90
90: ; preds = %13, %28, %39, %51, %63, %75, %87, %1
%91 = phi i32* [ null, %1 ], [ null, %13 ], [ null, %28 ], [ null, %39 ], [ null, %51 ], [ null, %63 ], [ null, %75 ], [ %11, %87 ]
ret i32* %91
}