#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 scalar_t__ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int sscanf(char *, char *, int *, int *, int *, int *, int *, int *);
int hwaddr_pton(char *mac, uint8_t *chaddr) {
  int values[6];
  int i;
  if (6 == sscanf(mac, "%x:%x:%x:%x:%x:%x%c", &values[0], &values[1],
                  &values[2], &values[3], &values[4], &values[5])) {
    for (i = 0; i < 6; ++i)
      chaddr[i] = (uint8_t)values[i];
  } else {
    perror("Invalid Mac");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<hwaddr_pton>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    -0x30(%rbp),%rcx
add    $0x4,%rcx
lea    -0x30(%rbp),%r8
add    $0x8,%r8
lea    -0x30(%rbp),%r9
add    $0xc,%r9
lea    -0x30(%rbp),%r10
add    $0x10,%r10
lea    -0x30(%rbp),%rax
add    $0x14,%rax
lea    0xe89(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0x6,%eax
cmp    %ecx,%eax
jne    11cd <hwaddr_pton+0x9d>
movl   $0x0,-0x34(%rbp)
cmpl   $0x6,-0x34(%rbp)
jge    11c8 <hwaddr_pton+0x98>
movslq -0x34(%rbp),%rax
movslq -0x30(%rbp,%rax,4),%rdx
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    119b <hwaddr_pton+0x6b>
jmp    11e3 <hwaddr_pton+0xb3>
lea    0xe40(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hwaddr_pton>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0x10(%rsp),%r10
lea    0x14(%rsp),%rax
lea    0xea8(%rip),%rsi
mov    %rsp,%rdx
push   %rax
push   %r10
call   1030 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x6,%eax
jne    11a6 <hwaddr_pton+0x76>
movslq (%rsp),%rax
mov    %rax,(%rbx)
movslq 0x4(%rsp),%rax
mov    %rax,0x8(%rbx)
movslq 0x8(%rsp),%rax
mov    %rax,0x10(%rbx)
movslq 0xc(%rsp),%rax
mov    %rax,0x18(%rbx)
movslq 0x10(%rsp),%rax
mov    %rax,0x20(%rbx)
movslq 0x14(%rsp),%rax
mov    %rax,0x28(%rbx)
add    $0x20,%rsp
pop    %rbx
ret
lea    0xe67(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@.str = [20 x i8] c"%x:%x:%x:%x:%x:%x%c\00"
@.str.1 = [12 x i8] c"Invalid Mac\00"
define i32 @hwaddr_pton(i8* nocapture %0, i64* nocapture writeonly %1) {
%3 = alloca [6 x i32]
%4 = bitcast [6 x i32]* %3 to i8*
%5 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%6 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 1
%7 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 2
%8 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 3
%9 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 4
%10 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 5
%11 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %6, i32* %7, i32* %8, i32* %9, i32* %10)
%12 = icmp eq i32 %11, 6
br i1 %12, label %13, label %31
13: ; preds = %2
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
store i64 %15, i64* %1
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i64, i64* %1, i64 1
store i64 %17, i64* %18
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i64, i64* %1, i64 2
store i64 %20, i64* %21
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i64, i64* %1, i64 3
store i64 %23, i64* %24
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i64, i64* %1, i64 4
store i64 %26, i64* %27
%28 = load i32, i32* %10
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i64, i64* %1, i64 5
store i64 %29, i64* %30
ret i32 undef
31: ; preds = %2
%32 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
}