#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int sscanf(char const *, char *, unsigned int *, unsigned int *, unsigned int *,
           unsigned int *, unsigned int *, unsigned int *);
int /*<<< orphan*/ stderr;
void scan_mac(const char *str, unsigned char *mac, unsigned add) {
  int i;
  unsigned int tmp[6];
  i = sscanf(str, "%2x:%2x:%2x:%2x:%2x:%2x", &tmp[0], &tmp[1], &tmp[2], &tmp[3],
             &tmp[4], &tmp[5]);
  if (i != 6) {
    fprintf(stderr, "format error (write MAC like this: 03:44:1a:ff:e5:70)\n");
    exit(3);
  }
  for (i = 0; i < 6; i++) {
    mac[i] = (unsigned char)(tmp[i]);
    if (i == 5)
      mac[i] -= (add ? 1 : 0);
  }
}


x86 assembly (clang, -O0):
<scan_mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%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    0xe86(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <sscanf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x6,-0x18(%rbp)
je     11b4 <scan_mac+0x84>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x3,%edi
call   1050 <exit@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x6,-0x18(%rbp)
jge    1218 <scan_mac+0xe8>
movslq -0x18(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
cmpl   $0x5,-0x18(%rbp)
jne    1205 <scan_mac+0xd5>
mov    -0x14(%rbp),%ecx
xor    %esi,%esi
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
sub    %esi,%edx
mov    %dl,(%rax,%rcx,1)
jmp    120a <scan_mac+0xda>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bb <scan_mac+0x8b>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_mac>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0x10(%rsp),%r10
lea    0x14(%rsp),%rax
lea    0xeb5(%rip),%rsi
mov    %rsp,%rdx
push   %rax
push   %r10
call   1040 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x6,%eax
jne    11a6 <scan_mac+0x76>
xor    %eax,%eax
test   %ebp,%ebp
setne  %al
movdqa (%rsp),%xmm0
pand   0xe7d(%rip),%xmm0
packuswb %xmm0,%xmm0
packuswb %xmm0,%xmm0
movd   %xmm0,(%rbx)
mov    0x10(%rsp),%cl
mov    %cl,0x4(%rbx)
mov    0x14(%rsp),%ecx
sub    %eax,%ecx
mov    %cl,0x5(%rbx)
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x3,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"%2x:%2x:%2x:%2x:%2x:%2x\00"
@stderr = global i32 0
@.str.1 = [55 x i8] c"format error (write MAC like this: 03:44:1a:ff:e5:70)\0A\00"
define void @scan_mac(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [6 x i32]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 0
%11 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 1
%12 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 2
%13 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 3
%14 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 4
%15 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 5
%16 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32* %10, i32* %11, i32* %12, i32* %13, i32* %14, i32* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 6
br i1 %18, label %19, label %23
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 3)
unreachable
23: ; preds = %3
store i32 0, i32* %7
br label %24
24: ; preds = %53, %23
%25 = load i32, i32* %7
%26 = icmp slt i32 %25, 6
br i1 %26, label %27, label %56
27: ; preds = %24
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [6 x i32], [6 x i32]* %8, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %5
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 %32, i8* %36
%37 = load i32, i32* %7
%38 = icmp eq i32 %37, 5
br i1 %38, label %39, label %52
39: ; preds = %27
%40 = load i32, i32* %6
%41 = icmp ne i32 %40, 0
%42 = zext i1 %41 to i64
%43 = select i1 %41, i32 1, i32 0
%44 = load i8*, i8** %5
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = sub nsw i32 %49, %43
%51 = trunc i32 %50 to i8
store i8 %51, i8* %47
br label %52
52: ; preds = %39, %27
br label %53
53: ; preds = %52
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
br label %24
56: ; preds = %24
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"%2x:%2x:%2x:%2x:%2x:%2x\00"
@stderr = global i32 0
@.str.1 = [55 x i8] c"format error (write MAC like this: 03:44:1a:ff:e5:70)\0A\00"
define void @scan_mac(i8* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = alloca [6 x i32]
%5 = bitcast [6 x i32]* %4 to i8*
%6 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 0
%7 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 1
%8 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 2
%9 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 3
%10 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 4
%11 = getelementptr inbounds [6 x i32], [6 x i32]* %4, i64 0, i64 5
%12 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32* %11)
%13 = icmp eq i32 %12, 6
br i1 %13, label %14, label %28
14: ; preds = %3
%15 = icmp ne i32 %2, 0
%16 = bitcast [6 x i32]* %4 to <4 x i32>*
%17 = load <4 x i32>, <4 x i32>* %16
%18 = trunc <4 x i32> %17 to <4 x i8>
%19 = bitcast i8* %1 to <4 x i8>*
store <4 x i8> %18, <4 x i8>* %19
%20 = load i32, i32* %10
%21 = getelementptr inbounds i8, i8* %1, i64 4
%22 = trunc i32 %20 to i8
store i8 %22, i8* %21
%23 = load i32, i32* %11
%24 = getelementptr inbounds i8, i8* %1, i64 5
%25 = sext i1 %15 to i32
%26 = add i32 %23, %25
%27 = trunc i32 %26 to i8
store i8 %27, i8* %24
ret void
28: ; preds = %3
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 3)
unreachable
}