#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 int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ addapessid(unsigned long long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int hex2bin(char *, int /*<<< orphan*/ *, int);
int ishexify(char *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ **, char *, int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ **, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int strlen(char *);
unsigned long long strtoull(char *, char **, int);
void readcommandline(char *macapname, char *essidname) {
  static int essidlen = 0;
  static int essidlenuh = 0;
  static char *macaddrstop = NULL;
  static unsigned long long int macaddr = 0xffffffffffffL;
  static uint8_t essid[32];
  if (macapname != NULL) {
    macaddr = strtoull(macapname, &macaddrstop, 16);
    if ((macaddrstop - macapname) != 12)
      fprintf(stderr, "invalid MAC specified\n");
  }
  memset(&essid, 0, 32);
  essidlen = strlen(essidname);
  if (essidname != NULL) {
    essidlenuh = ishexify(essidname);
    if ((essidlenuh > 0) && (essidlenuh <= 32)) {
      if (hex2bin(&essidname[5], essid, essidlenuh) == true)
        addapessid(macaddr, essidlenuh, essid);
      return;
    }
    memset(&essid, 0, 32);
    if (essidlen <= 32)
      memcpy(&essid, essidname, essidlen);
  }
  addapessid(macaddr, essidlen, essid);
  return;
}


x86 assembly (clang, -O0):
<readcommandline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11e9 <readcommandline+0x69>
mov    -0x8(%rbp),%rdi
lea    0x2ee2(%rip),%rsi
mov    $0x10,%edx
call   1060 <strtoull@plt>
mov    %rax,0x2ea9(%rip)
mov    0x2eca(%rip),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
cmp    $0xc,%rax
je     11e4 <readcommandline+0x64>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11e9 <readcommandline+0x69>
lea    0x2ea0(%rip),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,0x2e75(%rip)
cmpq   $0x0,-0x10(%rbp)
je     12bb <readcommandline+0x13b>
mov    -0x10(%rbp),%rdi
call   10a0 <ishexify@plt>
mov    %eax,0x2e5f(%rip)
cmpl   $0x0,0x2e58(%rip)
jle    1280 <readcommandline+0x100>
cmpl   $0x20,0x2e4b(%rip)
jg     1280 <readcommandline+0x100>
mov    -0x10(%rbp),%rdi
add    $0x5,%rdi
mov    0x2e37(%rip),%edx
lea    0x2e3c(%rip),%rsi
call   1030 <hex2bin@plt>
cmp    $0x1,%eax
jne    127b <readcommandline+0xfb>
mov    0x2df7(%rip),%rdi
mov    0x2e15(%rip),%esi
lea    0x2e1a(%rip),%rdx
call   1090 <addapessid@plt>
jmp    12d4 <readcommandline+0x154>
lea    0x2e09(%rip),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
cmpl   $0x20,0x2de6(%rip)
jg     12b6 <readcommandline+0x136>
mov    -0x10(%rbp),%rsi
mov    0x2dd6(%rip),%edx
lea    0x2ddf(%rip),%rdi
call   1080 <memcpy@plt>
jmp    12bb <readcommandline+0x13b>
mov    0x2d9e(%rip),%rdi
mov    0x2db8(%rip),%esi
lea    0x2dc1(%rip),%rdx
call   1090 <addapessid@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readcommandline>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
test   %rdi,%rdi
je     11cc <readcommandline+0x4c>
mov    %rdi,%rbx
lea    0x2ef2(%rip),%rsi
mov    $0x10,%edx
call   1060 <strtoull@plt>
mov    %rax,0x2eb9(%rip)
mov    0x2eda(%rip),%rax
sub    %rbx,%rax
cmp    $0xc,%rax
je     11cc <readcommandline+0x4c>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1070 <fprintf@plt>
lea    0x2ebd(%rip),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,0x2e93(%rip)
test   %r14,%r14
je     126d <readcommandline+0xed>
mov    %r14,%rdi
call   10a0 <ishexify@plt>
mov    %eax,0x2e84(%rip)
lea    -0x1(%rax),%ecx
cmp    $0x1f,%ecx
ja     1238 <readcommandline+0xb8>
add    $0x5,%r14
lea    0x2e7d(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   1030 <hex2bin@plt>
cmp    $0x1,%eax
jne    1289 <readcommandline+0x109>
mov    0x2e37(%rip),%rdi
mov    0x2e55(%rip),%esi
lea    0x2e5a(%rip),%rdx
jmp    127d <readcommandline+0xfd>
lea    0x2e51(%rip),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2e2f(%rip),%eax
cmp    $0x20,%eax
jg     126d <readcommandline+0xed>
lea    0x2e33(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1080 <memcpy@plt>
mov    0x2e13(%rip),%eax
mov    0x2dec(%rip),%rdi
lea    0x2e15(%rip),%rdx
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1090 <addapessid@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@readcommandline.essidlen = internal global i32 0
@readcommandline.essidlenuh = internal global i32 0
@readcommandline.macaddrstop = internal global i8* null
@readcommandline.macaddr = internal global i64 281474976710655
@readcommandline.essid = internal global [32 x i32] zeroinitializer
@stderr = global i32 0
@.str = [23 x i8] c"invalid MAC specified\0A\00"
define void @readcommandline(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %20
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = call i64 @strtoull(i8* %8, i8** @readcommandline.macaddrstop, i32 16)
store i64 %9, i64* @readcommandline.macaddr
%10 = load i8*, i8** @readcommandline.macaddrstop
%11 = load i8*, i8** %3
%12 = ptrtoint i8* %10 to i64
%13 = ptrtoint i8* %11 to i64
%14 = sub i64 %12, %13
%15 = icmp ne i64 %14, 12
br i1 %15, label %16, label %19
16: ; preds = %7
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %16, %7
br label %20
20: ; preds = %19, %2
%21 = call i32 @memset(i32** bitcast ([32 x i32]* @readcommandline.essid to i32**), i32 0, i32 32)
%22 = load i8*, i8** %4
%23 = call i32 @strlen(i8* %22)
store i32 %23, i32* @readcommandline.essidlen
%24 = load i8*, i8** %4
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %54
26: ; preds = %20
%27 = load i8*, i8** %4
%28 = call i32 @ishexify(i8* %27)
store i32 %28, i32* @readcommandline.essidlenuh
%29 = load i32, i32* @readcommandline.essidlenuh
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %45
31: ; preds = %26
%32 = load i32, i32* @readcommandline.essidlenuh
%33 = icmp sle i32 %32, 32
br i1 %33, label %34, label %45
34: ; preds = %31
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i64 5
%37 = load i32, i32* @readcommandline.essidlenuh
%38 = call i32 @hex2bin(i8* %36, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @readcommandline.essid, i64 0, i64 0), i32 %37)
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %44
40: ; preds = %34
%41 = load i64, i64* @readcommandline.macaddr
%42 = load i32, i32* @readcommandline.essidlenuh
%43 = call i32 @addapessid(i64 %41, i32 %42, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @readcommandline.essid, i64 0, i64 0))
br label %44
44: ; preds = %40, %34
br label %58
45: ; preds = %31, %26
%46 = call i32 @memset(i32** bitcast ([32 x i32]* @readcommandline.essid to i32**), i32 0, i32 32)
%47 = load i32, i32* @readcommandline.essidlen
%48 = icmp sle i32 %47, 32
br i1 %48, label %49, label %53
49: ; preds = %45
%50 = load i8*, i8** %4
%51 = load i32, i32* @readcommandline.essidlen
%52 = call i32 @memcpy(i32** bitcast ([32 x i32]* @readcommandline.essid to i32**), i8* %50, i32 %51)
br label %53
53: ; preds = %49, %45
br label %54
54: ; preds = %53, %20
%55 = load i64, i64* @readcommandline.macaddr
%56 = load i32, i32* @readcommandline.essidlen
%57 = call i32 @addapessid(i64 %55, i32 %56, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @readcommandline.essid, i64 0, i64 0))
br label %58
58: ; preds = %54, %44
ret void
}

LLVM IR (-O2):
@readcommandline.essidlen = internal unnamed_addr global i32 0
@readcommandline.essidlenuh = internal unnamed_addr global i32 0
@readcommandline.macaddrstop = internal global i8* null
@readcommandline.macaddr = internal unnamed_addr global i64 281474976710655
@readcommandline.essid = internal global [32 x i32] zeroinitializer
@stderr = global i32 0
@.str = [23 x i8] c"invalid MAC specified\0A\00"
define void @readcommandline(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %14, label %4
4: ; preds = %2
%5 = tail call i64 @strtoull(i8* %0, i8** @readcommandline.macaddrstop, i32 16)
store i64 %5, i64* @readcommandline.macaddr
%6 = load i8*, i8** @readcommandline.macaddrstop
%7 = ptrtoint i8* %6 to i64
%8 = ptrtoint i8* %0 to i64
%9 = sub i64 %7, %8
%10 = icmp eq i64 %9, 12
br i1 %10, label %14, label %11
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %4, %11, %2
%15 = tail call i32 @memset(i32** bitcast ([32 x i32]* @readcommandline.essid to i32**), i32 0, i32 32)
%16 = tail call i32 @strlen(i8* %1)
store i32 %16, i32* @readcommandline.essidlen
%17 = icmp eq i8* %1, null
br i1 %17, label %37, label %18
18: ; preds = %14
%19 = tail call i32 @ishexify(i8* %1)
store i32 %19, i32* @readcommandline.essidlenuh
%20 = add i32 %19, -1
%21 = icmp ult i32 %20, 32
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = getelementptr inbounds i8, i8* %1, i64 5
%24 = tail call i32 @hex2bin(i8* %23, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @readcommandline.essid, i64 0, i64 0), i32 %19)
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %41
26: ; preds = %22
%27 = load i64, i64* @readcommandline.macaddr
%28 = load i32, i32* @readcommandline.essidlenuh
%29 = tail call i32 @addapessid(i64 %27, i32 %28, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @readcommandline.essid, i64 0, i64 0))
br label %41
30: ; preds = %18
%31 = tail call i32 @memset(i32** bitcast ([32 x i32]* @readcommandline.essid to i32**), i32 0, i32 32)
%32 = load i32, i32* @readcommandline.essidlen
%33 = icmp slt i32 %32, 33
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = tail call i32 @memcpy(i32** bitcast ([32 x i32]* @readcommandline.essid to i32**), i8* %1, i32 %32)
%36 = load i32, i32* @readcommandline.essidlen
br label %37
37: ; preds = %30, %34, %14
%38 = phi i32 [ %32, %30 ], [ %36, %34 ], [ %16, %14 ]
%39 = load i64, i64* @readcommandline.macaddr
%40 = tail call i32 @addapessid(i64 %39, i32 %38, i32* getelementptr inbounds ([32 x i32], [32 x i32]* @readcommandline.essid, i64 0, i64 0))
br label %41
41: ; preds = %22, %26, %37
ret void
}