#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 parse_mac(char const *, unsigned char *);
int /*<<< orphan*/ print_mac(unsigned char *);
int /*<<< orphan*/ usage();
int maccalc_do_logical(int argc, const char *argv[],
                       unsigned char (*op)(unsigned char n1,
                                           unsigned char n2)) {
  unsigned char mac1[6];
  unsigned char mac2[6];
  int err;
  int i;
  if (argc != 2) {
    usage();
    return 1;
  }
  err = parse_mac(argv[0], mac1);
  if (err)
    return err;
  err = parse_mac(argv[1], mac2);
  if (err)
    return err;
  for (i = 0; i < 6; i++)
    mac1[i] = op(mac1[i], mac2[i]);
  print_mac(mac1);
  return 0;
}


x86 assembly (clang, -O0):
<maccalc_do_logical>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1160 <maccalc_do_logical+0x30>
mov    $0x0,%al
call   1050 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1204 <maccalc_do_logical+0xd4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x1e(%rbp),%rsi
call   1040 <parse_mac@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1188 <maccalc_do_logical+0x58>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1204 <maccalc_do_logical+0xd4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x24(%rbp),%rsi
call   1040 <parse_mac@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     11b1 <maccalc_do_logical+0x81>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1204 <maccalc_do_logical+0xd4>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x6,-0x2c(%rbp)
jge    11f4 <maccalc_do_logical+0xc4>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    -0x1e(%rbp,%rcx,1),%dl
movslq -0x2c(%rbp),%rcx
movzbl %dl,%edi
movzbl -0x24(%rbp,%rcx,1),%esi
call   *%rax
mov    %al,%cl
movslq -0x2c(%rbp),%rax
mov    %cl,-0x1e(%rbp,%rax,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b8 <maccalc_do_logical+0x88>
lea    -0x1e(%rbp),%rdi
call   1030 <print_mac@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maccalc_do_logical>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    11e5 <maccalc_do_logical+0xb5>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    (%rsi),%rdi
lea    0xc(%rsp),%rsi
call   1040 <parse_mac@plt>
test   %eax,%eax
jne    11f1 <maccalc_do_logical+0xc1>
mov    0x8(%rbx),%rdi
lea    0x12(%rsp),%rsi
call   1040 <parse_mac@plt>
test   %eax,%eax
jne    11f1 <maccalc_do_logical+0xc1>
movzbl 0xc(%rsp),%edi
movzbl 0x12(%rsp),%esi
call   *%r14
mov    %al,0xc(%rsp)
movzbl 0xd(%rsp),%edi
movzbl 0x13(%rsp),%esi
call   *%r14
mov    %al,0xd(%rsp)
movzbl 0xe(%rsp),%edi
movzbl 0x14(%rsp),%esi
call   *%r14
mov    %al,0xe(%rsp)
movzbl 0xf(%rsp),%edi
movzbl 0x15(%rsp),%esi
call   *%r14
mov    %al,0xf(%rsp)
movzbl 0x10(%rsp),%edi
movzbl 0x16(%rsp),%esi
call   *%r14
mov    %al,0x10(%rsp)
movzbl 0x11(%rsp),%edi
movzbl 0x17(%rsp),%esi
call   *%r14
mov    %al,0x11(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <print_mac@plt>
xor    %eax,%eax
jmp    11f1 <maccalc_do_logical+0xc1>
xor    %eax,%eax
call   1050 <usage@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @maccalc_do_logical(i32 %0, i8** %1, i8 (i8, i8)* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8 (i8, i8)*
%8 = alloca [6 x i8]
%9 = alloca [6 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8 (i8, i8)* %2, i8 (i8, i8)** %7
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 (...) @usage()
store i32 1, i32* %4
br label %60
16: ; preds = %3
%17 = load i8**, i8*** %6
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%21 = call i32 @parse_mac(i8* %19, i8* %20)
store i32 %21, i32* %10
%22 = load i32, i32* %10
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %16
%25 = load i32, i32* %10
store i32 %25, i32* %4
br label %60
26: ; preds = %16
%27 = load i8**, i8*** %6
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = getelementptr inbounds [6 x i8], [6 x i8]* %9, i64 0, i64 0
%31 = call i32 @parse_mac(i8* %29, i8* %30)
store i32 %31, i32* %10
%32 = load i32, i32* %10
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %26
%35 = load i32, i32* %10
store i32 %35, i32* %4
br label %60
36: ; preds = %26
store i32 0, i32* %11
br label %37
37: ; preds = %54, %36
%38 = load i32, i32* %11
%39 = icmp slt i32 %38, 6
br i1 %39, label %40, label %57
40: ; preds = %37
%41 = load i8 (i8, i8)*, i8 (i8, i8)** %7
%42 = load i32, i32* %11
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [6 x i8], [6 x i8]* %9, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = call zeroext i8 %41(i8 zeroext %45, i8 zeroext %49)
%51 = load i32, i32* %11
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 %52
store i8 %50, i8* %53
br label %54
54: ; preds = %40
%55 = load i32, i32* %11
%56 = add nsw i32 %55, 1
store i32 %56, i32* %11
br label %37
57: ; preds = %37
%58 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%59 = call i32 @print_mac(i8* %58)
store i32 0, i32* %4
br label %60
60: ; preds = %57, %34, %24, %14
%61 = load i32, i32* %4
ret i32 %61
}

LLVM IR (-O2):
define i32 @maccalc_do_logical(i32 %0, i8** nocapture %1, i8 (i8, i8)* nocapture %2) {
%4 = alloca [6 x i8]
%5 = alloca [6 x i8]
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%8 = icmp eq i32 %0, 2
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = tail call i32 (...) @usage()
br label %50
11: ; preds = %3
%12 = load i8*, i8** %1
%13 = call i32 @parse_mac(i8* %12, i8* %6)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %50
15: ; preds = %11
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @parse_mac(i8* %17, i8* %7)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %50
20: ; preds = %15
%21 = load i8, i8* %6
%22 = load i8, i8* %7
%23 = call zeroext i8 %2(i8 zeroext %21, i8 zeroext %22)
store i8 %23, i8* %6
%24 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 1
%25 = load i8, i8* %24
%26 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 1
%27 = load i8, i8* %26
%28 = call zeroext i8 %2(i8 zeroext %25, i8 zeroext %27)
store i8 %28, i8* %24
%29 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 2
%30 = load i8, i8* %29
%31 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 2
%32 = load i8, i8* %31
%33 = call zeroext i8 %2(i8 zeroext %30, i8 zeroext %32)
store i8 %33, i8* %29
%34 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 3
%35 = load i8, i8* %34
%36 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 3
%37 = load i8, i8* %36
%38 = call zeroext i8 %2(i8 zeroext %35, i8 zeroext %37)
store i8 %38, i8* %34
%39 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 4
%40 = load i8, i8* %39
%41 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 4
%42 = load i8, i8* %41
%43 = call zeroext i8 %2(i8 zeroext %40, i8 zeroext %42)
store i8 %43, i8* %39
%44 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 5
%45 = load i8, i8* %44
%46 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 5
%47 = load i8, i8* %46
%48 = call zeroext i8 %2(i8 zeroext %45, i8 zeroext %47)
store i8 %48, i8* %44
%49 = call i32 @print_mac(i8* %6)
br label %50
50: ; preds = %15, %11, %20, %9
%51 = phi i32 [ 1, %9 ], [ 0, %20 ], [ %13, %11 ], [ %18, %15 ]
ret i32 %51
}