#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 sscanf(char *, char *, unsigned int *, unsigned int *, unsigned int *,
           unsigned int *, unsigned int *, unsigned int *);
int atomac(char *str, unsigned char macAddr[6]) {
  unsigned mac[6];
  if (sscanf(str, "%2x:%2x:%2x:%2x:%2x:%2x", &mac[0], &mac[1], &mac[2], &mac[3],
             &mac[4], &mac[5]) != 6)
    return 1;
  int i;
  for (i = 0; i < 6; i++) {
    if (mac[i] > 0xff)
      return 1;
    macAddr[i] = (unsigned char)mac[i];
  }
  return 0;
}


x86 assembly (clang, -O0):
<atomac>:
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    0xea9(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <sscanf@plt>
cmp    $0x6,%eax
je     117a <atomac+0x6a>
movl   $0x1,-0x4(%rbp)
jmp    11d3 <atomac+0xc3>
movl   $0x0,-0x34(%rbp)
cmpl   $0x6,-0x34(%rbp)
jge    11cc <atomac+0xbc>
movslq -0x34(%rbp),%rax
cmpl   $0xff,-0x30(%rbp,%rax,4)
jbe    11a9 <atomac+0x99>
movl   $0x1,-0x4(%rbp)
jmp    11d3 <atomac+0xc3>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1181 <atomac+0x71>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atomac>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0x10(%rsp),%rax
lea    0x14(%rsp),%rbx
lea    0xec6(%rip),%rsi
mov    %rsp,%rdx
push   %rbx
push   %rax
call   1030 <sscanf@plt>
add    $0x10,%rsp
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x6,%ecx
jne    11b4 <atomac+0xa4>
mov    (%rsp),%ecx
cmp    $0xff,%ecx
ja     11b4 <atomac+0xa4>
mov    %cl,(%r14)
mov    0x4(%rsp),%ecx
cmp    $0xff,%ecx
ja     11b4 <atomac+0xa4>
mov    %cl,0x1(%r14)
mov    0x8(%rsp),%ecx
cmp    $0xff,%ecx
ja     11b4 <atomac+0xa4>
mov    %cl,0x2(%r14)
mov    0xc(%rsp),%ecx
cmp    $0xff,%ecx
ja     11b4 <atomac+0xa4>
mov    %cl,0x3(%r14)
mov    0x10(%rsp),%ecx
cmp    $0xff,%ecx
ja     11b4 <atomac+0xa4>
mov    %cl,0x4(%r14)
mov    0x14(%rsp),%ecx
cmp    $0xff,%ecx
ja     11b4 <atomac+0xa4>
mov    %cl,0x5(%r14)
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [24 x i8] c"%2x:%2x:%2x:%2x:%2x:%2x\00"
define i32 @atomac(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [6 x i32]
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %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 ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32* %9, i32* %10, i32* %11, i32* %12, i32* %13, i32* %14)
%16 = icmp ne i32 %15, 6
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 1, i32* %3
br label %43
18: ; preds = %2
store i32 0, i32* %7
br label %19
19: ; preds = %39, %18
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 6
br i1 %21, label %22, label %42
22: ; preds = %19
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = icmp ugt i32 %26, 255
br i1 %27, label %28, label %29
28: ; preds = %22
store i32 1, i32* %3
br label %43
29: ; preds = %22
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [6 x i32], [6 x i32]* %6, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = trunc i32 %33 to i8
%35 = load i8*, i8** %5
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 %34, i8* %38
br label %39
39: ; preds = %29
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %19
42: ; preds = %19
store i32 0, i32* %3
br label %43
43: ; preds = %42, %28, %17
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [24 x i8] c"%2x:%2x:%2x:%2x:%2x:%2x\00"
define i32 @atomac(i8* nocapture %0, i8* 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 ([24 x i8], [24 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 %43
13: ; preds = %2
%14 = load i32, i32* %5
%15 = icmp ugt i32 %14, 255
br i1 %15, label %43, label %16
16: ; preds = %13
%17 = trunc i32 %14 to i8
store i8 %17, i8* %1
%18 = load i32, i32* %6
%19 = icmp ugt i32 %18, 255
br i1 %19, label %43, label %20
20: ; preds = %16
%21 = trunc i32 %18 to i8
%22 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %21, i8* %22
%23 = load i32, i32* %7
%24 = icmp ugt i32 %23, 255
br i1 %24, label %43, label %25
25: ; preds = %20
%26 = trunc i32 %23 to i8
%27 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %26, i8* %27
%28 = load i32, i32* %8
%29 = icmp ugt i32 %28, 255
br i1 %29, label %43, label %30
30: ; preds = %25
%31 = trunc i32 %28 to i8
%32 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %31, i8* %32
%33 = load i32, i32* %9
%34 = icmp ugt i32 %33, 255
br i1 %34, label %43, label %35
35: ; preds = %30
%36 = trunc i32 %33 to i8
%37 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %36, i8* %37
%38 = load i32, i32* %10
%39 = icmp ugt i32 %38, 255
br i1 %39, label %43, label %40
40: ; preds = %35
%41 = trunc i32 %38 to i8
%42 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %41, i8* %42
br label %43
43: ; preds = %13, %16, %20, %25, %30, %35, %40, %2
%44 = phi i32 [ 1, %2 ], [ 1, %13 ], [ 1, %16 ], [ 1, %20 ], [ 1, %25 ], [ 1, %30 ], [ 1, %35 ], [ 0, %40 ]
ret i32 %44
}