#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 */
scalar_t__ isxdigit(char const);
int sscanf(char *, char *, int *);
int strlen(char const *);
int conv_macaddress_str_to_bin(const char *optarg,
                               unsigned char macaddress[6]) {
  int i, v;
  char xstr[3] = {};
  if (strlen(optarg) != 17) {
    return 0;
  }
  for (i = 0; i < 6; i++, optarg += 3) {
    int isok = isxdigit(optarg[0]) && isxdigit(optarg[1]) &&
               (i == 5 ? 1 : optarg[2] == ':' || optarg[2] == '-');
    if (!isok) {
      return 0;
    }
    xstr[0] = optarg[0];
    xstr[1] = optarg[1];
    if (sscanf(xstr, "%2x", &v) == 1) {
      macaddress[i] = v & 0xffu;
    } else {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<conv_macaddress_str_to_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x23(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x11,%eax
je     117e <conv_macaddress_str_to_bin+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    12be <conv_macaddress_str_to_bin+0x17e>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x6,-0x1c(%rbp)
jge    12b7 <conv_macaddress_str_to_bin+0x177>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isxdigit@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x29(%rbp)
je     1221 <conv_macaddress_str_to_bin+0xe1>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1060 <isxdigit@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x29(%rbp)
je     1221 <conv_macaddress_str_to_bin+0xe1>
cmpl   $0x5,-0x1c(%rbp)
jne    11e3 <conv_macaddress_str_to_bin+0xa3>
mov    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1215 <conv_macaddress_str_to_bin+0xd5>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%ecx
mov    $0x1,%al
cmp    $0x3a,%ecx
mov    %al,-0x31(%rbp)
je     120a <conv_macaddress_str_to_bin+0xca>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x2d,%eax
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    1242 <conv_macaddress_str_to_bin+0x102>
movl   $0x0,-0x4(%rbp)
jmp    12be <conv_macaddress_str_to_bin+0x17e>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x23(%rbp)
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x22(%rbp)
lea    -0x23(%rbp),%rdi
lea    0xda0(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    128c <conv_macaddress_str_to_bin+0x14c>
mov    -0x20(%rbp),%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1298 <conv_macaddress_str_to_bin+0x158>
movl   $0x0,-0x4(%rbp)
jmp    12be <conv_macaddress_str_to_bin+0x17e>
jmp    129d <conv_macaddress_str_to_bin+0x15d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
jmp    1185 <conv_macaddress_str_to_bin+0x45>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conv_macaddress_str_to_bin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rbp
movb   $0x0,0x3(%rsp)
call   1030 <strlen@plt>
xor    %ecx,%ecx
cmp    $0x11,%eax
jne    11ed <conv_macaddress_str_to_bin+0xbd>
add    $0x2,%rbp
mov    $0xfffffffffffffffa,%r14
lea    0xe98(%rip),%r15
lea    0x1(%rsp),%r12
lea    0x4(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl -0x2(%rbp),%edi
call   1050 <isxdigit@plt>
test   %rax,%rax
je     11eb <conv_macaddress_str_to_bin+0xbb>
movsbl -0x1(%rbp),%edi
call   1050 <isxdigit@plt>
test   %rax,%rax
je     11eb <conv_macaddress_str_to_bin+0xbb>
cmp    $0xffffffffffffffff,%r14
je     11ae <conv_macaddress_str_to_bin+0x7e>
movzbl 0x0(%rbp),%eax
cmp    $0x3a,%al
je     11ae <conv_macaddress_str_to_bin+0x7e>
cmp    $0x2d,%al
jne    11eb <conv_macaddress_str_to_bin+0xbb>
movzbl -0x2(%rbp),%eax
mov    %al,0x1(%rsp)
movzbl -0x1(%rbp),%eax
mov    %al,0x2(%rsp)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    11eb <conv_macaddress_str_to_bin+0xbb>
movzbl 0x4(%rsp),%eax
mov    %al,0x6(%rbx,%r14,1)
add    $0x3,%rbp
inc    %r14
jne    1180 <conv_macaddress_str_to_bin+0x50>
mov    $0x1,%ecx
jmp    11ed <conv_macaddress_str_to_bin+0xbd>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%2x\00"
define i32 @conv_macaddress_str_to_bin(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [3 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = bitcast [3 x i8]* %8 to i8*
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = icmp ne i32 %12, 17
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 0, i32* %3
br label %87
15: ; preds = %2
store i32 0, i32* %6
br label %16
16: ; preds = %81, %15
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 6
br i1 %18, label %19, label %86
19: ; preds = %16
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = call i64 @isxdigit(i8 signext %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %53
25: ; preds = %19
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = call i64 @isxdigit(i8 signext %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %53
31: ; preds = %25
%32 = load i32, i32* %6
%33 = icmp eq i32 %32, 5
br i1 %33, label %34, label %35
34: ; preds = %31
br label %50
35: ; preds = %31
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 2
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 58
br i1 %40, label %47, label %41
41: ; preds = %35
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i64 2
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 45
br label %47
47: ; preds = %41, %35
%48 = phi i1 [ true, %35 ], [ %46, %41 ]
%49 = zext i1 %48 to i32
br label %50
50: ; preds = %47, %34
%51 = phi i32 [ 1, %34 ], [ %49, %47 ]
%52 = icmp ne i32 %51, 0
br label %53
53: ; preds = %50, %25, %19
%54 = phi i1 [ false, %25 ], [ false, %19 ], [ %52, %50 ]
%55 = zext i1 %54 to i32
store i32 %55, i32* %9
%56 = load i32, i32* %9
%57 = icmp ne i32 %56, 0
br i1 %57, label %59, label %58
58: ; preds = %53
store i32 0, i32* %3
br label %87
59: ; preds = %53
%60 = load i8*, i8** %4
%61 = getelementptr inbounds i8, i8* %60, i64 0
%62 = load i8, i8* %61
%63 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
store i8 %62, i8* %63
%64 = load i8*, i8** %4
%65 = getelementptr inbounds i8, i8* %64, i64 1
%66 = load i8, i8* %65
%67 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 1
store i8 %66, i8* %67
%68 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%69 = call i32 @sscanf(i8* %68, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %7)
%70 = icmp eq i32 %69, 1
br i1 %70, label %71, label %79
71: ; preds = %59
%72 = load i32, i32* %7
%73 = and i32 %72, 255
%74 = trunc i32 %73 to i8
%75 = load i8*, i8** %5
%76 = load i32, i32* %6
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %75, i64 %77
store i8 %74, i8* %78
br label %80
79: ; preds = %59
store i32 0, i32* %3
br label %87
80: ; preds = %71
br label %81
81: ; preds = %80
%82 = load i32, i32* %6
%83 = add nsw i32 %82, 1
store i32 %83, i32* %6
%84 = load i8*, i8** %4
%85 = getelementptr inbounds i8, i8* %84, i64 3
store i8* %85, i8** %4
br label %16
86: ; preds = %16
store i32 1, i32* %3
br label %87
87: ; preds = %86, %79, %58, %14
%88 = load i32, i32* %3
ret i32 %88
}

LLVM IR (-O2):
@.str = [4 x i8] c"%2x\00"
define i32 @conv_macaddress_str_to_bin(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca [3 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
store i8 0, i8* %7
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp eq i32 %8, 17
br i1 %9, label %10, label %40
10: ; preds = %2
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
br label %12
12: ; preds = %10, %33
%13 = phi i64 [ 0, %10 ], [ %37, %33 ]
%14 = phi i8* [ %0, %10 ], [ %38, %33 ]
%15 = load i8, i8* %14
%16 = call i64 @isxdigit(i8 signext %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %40, label %18
18: ; preds = %12
%19 = getelementptr inbounds i8, i8* %14, i64 1
%20 = load i8, i8* %19
%21 = call i64 @isxdigit(i8 signext %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %40, label %23
23: ; preds = %18
%24 = icmp eq i64 %13, 5
br i1 %24, label %28, label %25
25: ; preds = %23
%26 = getelementptr inbounds i8, i8* %14, i64 2
%27 = load i8, i8* %26
switch i8 %27, label %40 [
i8 58, label %28
i8 45, label %28
]
28: ; preds = %25, %25, %23
%29 = load i8, i8* %14
store i8 %29, i8* %6
%30 = load i8, i8* %19
store i8 %30, i8* %11
%31 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %40
33: ; preds = %28
%34 = load i32, i32* %3
%35 = trunc i32 %34 to i8
%36 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 %35, i8* %36
%37 = add nuw nsw i64 %13, 1
%38 = getelementptr inbounds i8, i8* %14, i64 3
%39 = icmp eq i64 %37, 6
br i1 %39, label %40, label %12
40: ; preds = %25, %12, %18, %33, %28, %2
%41 = phi i32 [ 0, %2 ], [ 0, %12 ], [ 0, %18 ], [ 1, %33 ], [ 0, %25 ], [ 0, %28 ]
ret i32 %41
}