#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 */
char *mac_encode(char *);
char *mac_get_hex(char *);
char *mac_get_oui(char *);
char *mac_get_vendor(char *);
int /*<<< orphan*/ mac_init();
char *mac_obfuscate(char *);
char *mac_rand();
scalar_t__ mac_verify(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int i;
  char *addr_buffer = {0};
  int runs = 5;
  mac_init();
  addr_buffer = "F0:DE:F1:B7:0E:F6";
  printf("MAC: %s\n", addr_buffer);
  printf("----------------------------\n");
  if (mac_verify(mac_get_hex(addr_buffer)) == 0)
    printf("This is a valid MAC.\n");
  else
    printf("This is not a valid MAC!\n");
  printf("OUI: %s\n", mac_get_oui(addr_buffer));
  printf("CRC: %s\n", mac_encode(addr_buffer));
  printf("Anonymized: %s\n", mac_obfuscate(addr_buffer));
  printf("HEX notation: %s\n", mac_get_hex(addr_buffer));
  printf("Manufacturer: %s\n", mac_get_vendor(addr_buffer));
  printf("\n");
  printf("Random MACs:\n");
  for (i = 1; i <= runs; i++) {
    addr_buffer = mac_rand();
    printf("%s\n", addr_buffer);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x5,-0x14(%rbp)
mov    $0x0,%al
call   1030 <mac_init@plt>
lea    0xe44(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <mac_get_hex@plt>
mov    %rax,%rdi
call   1070 <mac_verify@plt>
cmp    $0x0,%rax
jne    120e <main+0x7e>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121c <main+0x8c>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <mac_get_oui@plt>
mov    %rax,%rsi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <mac_encode@plt>
mov    %rax,%rsi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <mac_obfuscate@plt>
mov    %rax,%rsi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <mac_get_hex@plt>
mov    %rax,%rsi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1090 <mac_get_vendor@plt>
mov    %rax,%rsi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     12f8 <main+0x168>
mov    $0x0,%al
call   1050 <mac_rand@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12c1 <main+0x131>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1030 <mac_init@plt>
lea    0xe53(%rip),%rdi
lea    0xe3a(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe8a(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   10d0 <mac_get_hex@plt>
mov    %rax,%rdi
call   1090 <mac_verify@plt>
test   %rax,%rax
lea    0xeae(%rip),%rax
lea    0xe81(%rip),%rdi
cmove  %rax,%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   10c0 <mac_get_oui@plt>
lea    0xe06(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1080 <mac_encode@plt>
lea    0xdf6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   10a0 <mac_obfuscate@plt>
lea    0xde6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   10d0 <mac_get_hex@plt>
lea    0xddd(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   10b0 <mac_get_vendor@plt>
lea    0xdd6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xe03(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1070 <mac_rand@plt>
mov    %rax,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1070 <mac_rand@plt>
mov    %rax,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1070 <mac_rand@plt>
mov    %rax,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1070 <mac_rand@plt>
mov    %rax,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1070 <mac_rand@plt>
mov    %rax,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"F0:DE:F1:B7:0E:F6\00"
@.str.1 = [9 x i8] c"MAC: %s\0A\00"
@.str.2 = [30 x i8] c"----------------------------\0A\00"
@.str.3 = [22 x i8] c"This is a valid MAC.\0A\00"
@.str.4 = [26 x i8] c"This is not a valid MAC!\0A\00"
@.str.5 = [9 x i8] c"OUI: %s\0A\00"
@.str.6 = [9 x i8] c"CRC: %s\0A\00"
@.str.7 = [16 x i8] c"Anonymized: %s\0A\00"
@.str.8 = [18 x i8] c"HEX notation: %s\0A\00"
@.str.9 = [18 x i8] c"Manufacturer: %s\0A\00"
@.str.10 = [2 x i8] c"\0A\00"
@.str.11 = [14 x i8] c"Random MACs:\0A\00"
@.str.12 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
store i8* null, i8** %3
store i32 5, i32* %4
%5 = call i32 (...) @mac_init()
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %3
%6 = load i8*, i8** %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%9 = load i8*, i8** %3
%10 = call i8* @mac_get_hex(i8* %9)
%11 = call i64 @mac_verify(i8* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %17
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %17
17: ; preds = %15, %13
%18 = load i8*, i8** %3
%19 = call i8* @mac_get_oui(i8* %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %3
%22 = call i8* @mac_encode(i8* %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %3
%25 = call i8* @mac_obfuscate(i8* %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %3
%28 = call i8* @mac_get_hex(i8* %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i8* %28)
%30 = load i8*, i8** %3
%31 = call i8* @mac_get_vendor(i8* %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i8* %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %2
br label %35
35: ; preds = %43, %17
%36 = load i32, i32* %2
%37 = load i32, i32* %4
%38 = icmp sle i32 %36, %37
br i1 %38, label %39, label %46
39: ; preds = %35
%40 = call i8* (...) @mac_rand()
store i8* %40, i8** %3
%41 = load i8*, i8** %3
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %39
%44 = load i32, i32* %2
%45 = add nsw i32 %44, 1
store i32 %45, i32* %2
br label %35
46: ; preds = %35
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"F0:DE:F1:B7:0E:F6\00"
@.str.1 = [9 x i8] c"MAC: %s\0A\00"
@.str.5 = [9 x i8] c"OUI: %s\0A\00"
@.str.6 = [9 x i8] c"CRC: %s\0A\00"
@.str.7 = [16 x i8] c"Anonymized: %s\0A\00"
@.str.8 = [18 x i8] c"HEX notation: %s\0A\00"
@.str.9 = [18 x i8] c"Manufacturer: %s\0A\00"
@str = [29 x i8] c"----------------------------\00"
@str.13 = [25 x i8] c"This is not a valid MAC!\00"
@str.14 = [13 x i8] c"Random MACs:\00"
@str.15 = [21 x i8] c"This is a valid MAC.\00"
define i32 @main() {
%1 = tail call i32 (...) @mac_init()
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%4 = tail call i8* @mac_get_hex(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%5 = tail call i64 @mac_verify(i8* %4)
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @str.15, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @str.13, i64 0, i64 0)
%8 = tail call i32 @puts(i8* dereferenceable(1) %7)
%9 = tail call i8* @mac_get_oui(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %9)
%11 = tail call i8* @mac_encode(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %11)
%13 = tail call i8* @mac_obfuscate(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %13)
%15 = tail call i8* @mac_get_hex(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i8* %15)
%17 = tail call i8* @mac_get_vendor(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i8* %17)
%19 = tail call i32 @putchar(i32 10)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.14, i64 0, i64 0))
%21 = tail call i8* (...) @mac_rand()
%22 = tail call i32 @puts(i8* dereferenceable(1) %21)
%23 = tail call i8* (...) @mac_rand()
%24 = tail call i32 @puts(i8* dereferenceable(1) %23)
%25 = tail call i8* (...) @mac_rand()
%26 = tail call i32 @puts(i8* dereferenceable(1) %25)
%27 = tail call i8* (...) @mac_rand()
%28 = tail call i32 @puts(i8* dereferenceable(1) %27)
%29 = tail call i8* (...) @mac_rand()
%30 = tail call i32 @puts(i8* dereferenceable(1) %29)
ret i32 0
}