#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 ssize_t;
typedef int /*<<< orphan*/ mac;

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int parse_mac(char const *, unsigned char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int write(int /*<<< orphan*/, unsigned char *, int);
int maccalc_do_mac2bin(int argc, const char *argv[]) {
  unsigned char mac[6];
  ssize_t c;
  int err;
  if (argc != 1) {
    usage();
    return 1;
  }
  err = parse_mac(argv[0], mac);
  if (err)
    return err;
  c = write(STDOUT_FILENO, mac, sizeof(mac));
  if (c != sizeof(mac)) {
    fprintf(stderr, "failed to write to stdout\n");
    return 2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<maccalc_do_mac2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     116c <maccalc_do_mac2bin+0x2c>
mov    $0x0,%al
call   1060 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e4 <maccalc_do_mac2bin+0xa4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x16(%rbp),%rsi
call   1040 <parse_mac@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1194 <maccalc_do_mac2bin+0x54>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e4 <maccalc_do_mac2bin+0xa4>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    -0x16(%rbp),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0x6,%rax
je     11dd <maccalc_do_mac2bin+0x9d>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11e4 <maccalc_do_mac2bin+0xa4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maccalc_do_mac2bin>:
push   %rax
cmp    $0x1,%edi
jne    1159 <maccalc_do_mac2bin+0x19>
mov    (%rsi),%rdi
lea    0x2(%rsp),%rsi
call   1040 <parse_mac@plt>
test   %eax,%eax
je     1167 <maccalc_do_mac2bin+0x27>
pop    %rcx
ret
xor    %eax,%eax
call   1060 <usage@plt>
mov    $0x1,%eax
pop    %rcx
ret
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    0x2(%rsp),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x6,%ecx
je     1157 <maccalc_do_mac2bin+0x17>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%eax
pop    %rcx
ret

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"failed to write to stdout\0A\00"
define i32 @maccalc_do_mac2bin(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [6 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (...) @usage()
store i32 1, i32* %3
br label %34
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%18 = call i32 @parse_mac(i8* %16, i8* %17)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = load i32, i32* %8
store i32 %22, i32* %3
br label %34
23: ; preds = %13
%24 = load i32, i32* @STDOUT_FILENO
%25 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%26 = call i32 @write(i32 %24, i8* %25, i32 6)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = icmp ne i64 %28, 6
br i1 %29, label %30, label %33
30: ; preds = %23
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %3
br label %34
33: ; preds = %23
store i32 0, i32* %3
br label %34
34: ; preds = %33, %30, %21, %11
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"failed to write to stdout\0A\00"
define i32 @maccalc_do_mac2bin(i32 %0, i8** nocapture %1) {
%3 = alloca [6 x i8]
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 1
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (...) @usage()
br label %19
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = call i32 @parse_mac(i8* %9, i8* %4)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = load i32, i32* @STDOUT_FILENO
%14 = call i32 @write(i32 %13, i8* %4, i32 6)
%15 = icmp eq i32 %14, 6
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %12, %8, %16, %6
%20 = phi i32 [ 1, %6 ], [ 2, %16 ], [ %10, %8 ], [ 0, %12 ]
ret i32 %20
}