#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*/ isValidMacAddr(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ string_to_hex(char *, char *, int);
int strlen(char *);
int mac17ToMac6(char *mac17, char *mac6) {
  int i;
  for (i = 0; i < 17; i++) {
    if ((i + 1) % 3 != 0)
      mac17[i - (i + 1) / 3] = mac17[i];
  }
  mac17[12] = '\0';
  if (strlen(mac17) != 12 || !string_to_hex(mac17, mac6, 12) ||
      !isValidMacAddr(mac6)) {
    printf("Error! Invalid MAC address.");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<mac17ToMac6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x11,-0x1c(%rbp)
jge    11c3 <mac17ToMac6+0x83>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11b0 <mac17ToMac6+0x70>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    $0x3,%esi
cltd
idiv   %esi
mov    -0x29(%rbp),%dl
mov    %eax,%esi
mov    -0x28(%rbp),%rax
sub    %esi,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11b5 <mac17ToMac6+0x75>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1157 <mac17ToMac6+0x17>
mov    -0x10(%rbp),%rax
movb   $0x0,0xc(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0xc,%eax
jne    120a <mac17ToMac6+0xca>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1050 <string_to_hex@plt>
cmp    $0x0,%eax
je     120a <mac17ToMac6+0xca>
mov    -0x18(%rbp),%rdi
call   1060 <isValidMacAddr@plt>
cmp    $0x0,%eax
jne    1222 <mac17ToMac6+0xe2>
lea    0xdef(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <mac17ToMac6+0xe9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mac17ToMac6>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x1,%ecx
xor    %r10d,%r10d
movabs $0xaaaaaaaaaaaaaaab,%r8
aa aa aa
movabs $0x100000000,%r9
xor    %edi,%edi
jmp    1180 <mac17ToMac6+0x40>
nopl   0x0(%rax,%rax,1)
add    %r9,%r10
add    $0x1,%rcx
mov    %rax,%rdi
cmp    $0x11,%rax
je     11be <mac17ToMac6+0x7e>
mov    %rcx,%rax
mul    %r8
lea    0x1(%rdi),%rax
movzbl %cl,%ebx
imul   $0xab,%ebx,%ebx
shr    $0x9,%ebx
lea    (%rbx,%rbx,2),%ebx
add    $0xff,%bl
cmp    %dil,%bl
je     1170 <mac17ToMac6+0x30>
and    $0xfffffffffffffffe,%rdx
shl    $0x1f,%rdx
mov    %r10,%rsi
sub    %rdx,%rsi
movzbl (%r15,%rdi,1),%edx
sar    $0x20,%rsi
mov    %dl,(%r15,%rsi,1)
jmp    1170 <mac17ToMac6+0x30>
movb   $0x0,0xc(%r15)
mov    %r15,%rdi
call   1030 <strlen@plt>
cmp    $0xc,%eax
jne    11f4 <mac17ToMac6+0xb4>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0xc,%edx
call   1050 <string_to_hex@plt>
test   %eax,%eax
je     11f4 <mac17ToMac6+0xb4>
mov    %r14,%rdi
call   1060 <isValidMacAddr@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jne    1205 <mac17ToMac6+0xc5>
lea    0xe05(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Error! Invalid MAC address.\00"
define i32 @mac17ToMac6(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
br label %7
7: ; preds = %30, %2
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 17
br i1 %9, label %10, label %33
10: ; preds = %7
%11 = load i32, i32* %6
%12 = add nsw i32 %11, 1
%13 = srem i32 %12, 3
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = load i8*, i8** %4
%22 = load i32, i32* %6
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
%25 = sdiv i32 %24, 3
%26 = sub nsw i32 %22, %25
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %21, i64 %27
store i8 %20, i8* %28
br label %29
29: ; preds = %15, %10
br label %30
30: ; preds = %29
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %7
33: ; preds = %7
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 12
store i8 0, i8* %35
%36 = load i8*, i8** %4
%37 = call i32 @strlen(i8* %36)
%38 = icmp ne i32 %37, 12
br i1 %38, label %48, label %39
39: ; preds = %33
%40 = load i8*, i8** %4
%41 = load i8*, i8** %5
%42 = call i32 @string_to_hex(i8* %40, i8* %41, i32 12)
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %39
%45 = load i8*, i8** %5
%46 = call i32 @isValidMacAddr(i8* %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %50, label %48
48: ; preds = %44, %39, %33
%49 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %51
50: ; preds = %44
store i32 0, i32* %3
br label %51
51: ; preds = %50, %48
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [28 x i8] c"Error! Invalid MAC address.\00"
define i32 @mac17ToMac6(i8* %0, i8* %1) {
br label %3
3: ; preds = %2, %18
%4 = phi i64 [ 0, %2 ], [ %5, %18 ]
%5 = add nuw nsw i64 %4, 1
%6 = trunc i64 %5 to i8
%7 = urem i8 %6, 3
%8 = udiv i8 %6, 3
%9 = icmp eq i8 %7, 0
br i1 %9, label %18, label %10
10: ; preds = %3
%11 = getelementptr inbounds i8, i8* %0, i64 %4
%12 = load i8, i8* %11
%13 = zext i8 %8 to i64
%14 = sub nsw i64 %4, %13
%15 = shl i64 %14, 32
%16 = ashr exact i64 %15, 32
%17 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 %12, i8* %17
br label %18
18: ; preds = %3, %10
%19 = icmp eq i64 %5, 17
br i1 %19, label %20, label %3
20: ; preds = %18
%21 = getelementptr inbounds i8, i8* %0, i64 12
store i8 0, i8* %21
%22 = tail call i32 @strlen(i8* %0)
%23 = icmp eq i32 %22, 12
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = tail call i32 @string_to_hex(i8* %0, i8* %1, i32 12)
%26 = icmp eq i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = tail call i32 @isValidMacAddr(i8* %1)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27, %24, %20
%31 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %27, %30
%33 = phi i32 [ -1, %30 ], [ 0, %27 ]
ret i32 %33
}