#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*/ STDIN_FILENO;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ print_mac(unsigned char *);
int read(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int maccalc_do_bin2mac(int argc, const char *argv[]) {
  unsigned char mac[6];
  ssize_t c;
  if (argc != 0) {
    usage();
    return 1;
  }
  c = read(STDIN_FILENO, mac, sizeof(mac));
  if (c != sizeof(mac)) {
    fprintf(stderr, "failed to read from stdin\n");
    return 2;
  }
  print_mac(mac);
  return 0;
}


x86 assembly (clang, -O0):
<maccalc_do_bin2mac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     116c <maccalc_do_bin2mac+0x2c>
mov    $0x0,%al
call   1060 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c5 <maccalc_do_bin2mac+0x85>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    -0x16(%rbp),%rsi
mov    $0x6,%edx
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0x6,%rax
je     11b5 <maccalc_do_bin2mac+0x75>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11c5 <maccalc_do_bin2mac+0x85>
lea    -0x16(%rbp),%rdi
call   1030 <print_mac@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maccalc_do_bin2mac>:
push   %rax
test   %edi,%edi
je     1153 <maccalc_do_bin2mac+0x13>
xor    %eax,%eax
call   1060 <usage@plt>
mov    $0x1,%eax
pop    %rcx
ret
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0x2(%rsp),%rsi
mov    $0x6,%edx
call   1040 <read@plt>
cmp    $0x6,%eax
jne    117e <maccalc_do_bin2mac+0x3e>
lea    0x2(%rsp),%rdi
call   1030 <print_mac@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"failed to read from stdin\0A\00"
define i32 @maccalc_do_bin2mac(i32 %0, i8** nocapture readnone %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, 0
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (...) @usage()
br label %17
8: ; preds = %2
%9 = load i32, i32* @STDIN_FILENO
%10 = call i32 @read(i32 %9, i8* %4, i32 6)
%11 = icmp eq i32 %10, 6
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %17
15: ; preds = %8
%16 = call i32 @print_mac(i8* %4)
br label %17
17: ; preds = %15, %12, %6
%18 = phi i32 [ 1, %6 ], [ 2, %12 ], [ 0, %15 ]
ret i32 %18
}