#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ feof(int /*<<< orphan*/);
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ frame(unsigned char *, unsigned char *, int,
                         unsigned char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/);
int htonl(int);
int /*<<< orphan*/ memcpy(unsigned char *, int *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int readmac(char *, unsigned char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  if (argc != 3) {
    usage(argv[0]);
  }
  int count, i, netsum, total = 0;
  register int checksum = 0;
  unsigned char buf[1500];
  unsigned char dst[6];
  unsigned char src[6];
  if (readmac(argv[1], dst) != 1 || readmac(argv[2], src) != 1) {
    perror("argument error");
    exit(EXIT_FAILURE);
  }
  while (!feof(stdin)) {
    count = fread(buf, sizeof(char), 1500, stdin);
    if (ferror(stdin)) {
      perror("read error");
      exit(EXIT_FAILURE);
    }
    frame(dst, src, count, buf);
    printf("\n");
    for (i = 0; i < sizeof(buf); i++) {
      checksum += buf[i];
    }
    total += count;
  }
  netsum = htonl(checksum);
  memcpy(buf, &netsum, 4);
  memset(buf + 4, 0, 1500 - 4);
  frame(dst, src, 1500, buf);
  printf("\n");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x610,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11ef <main+0x2f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <usage@plt>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x606(%rbp),%rsi
call   1080 <readmac@plt>
cmp    $0x1,%eax
jne    1237 <main+0x77>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x60c(%rbp),%rsi
call   1080 <readmac@plt>
cmp    $0x1,%eax
je     1251 <main+0x91>
lea    0xdc2(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
jmp    1256 <main+0x96>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   10a0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1279 <main+0xb9>
jmp    133b <main+0x17b>
lea    -0x600(%rbp),%rdi
mov    0x2d61(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x5dc,%edx
call   1040 <fread@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12cd <main+0x10d>
lea    0xd55(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    -0x606(%rbp),%rdi
lea    -0x60c(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x600(%rbp),%rcx
call   1090 <frame@plt>
lea    0xd29(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    $0x5dc,%rax
jae    132d <main+0x16d>
movslq -0x18(%rbp),%rax
movzbl -0x600(%rbp,%rax,1),%eax
ff
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12fd <main+0x13d>
mov    -0x14(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1256 <main+0x96>
mov    -0x24(%rbp),%edi
call   1060 <htonl@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x600(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <memcpy@plt>
lea    -0x600(%rbp),%rdi
add    $0x4,%rdi
xor    %esi,%esi
mov    $0x5d8,%edx
call   1070 <memset@plt>
lea    -0x606(%rbp),%rdi
lea    -0x60c(%rbp),%rsi
lea    -0x600(%rbp),%rcx
mov    $0x5dc,%edx
call   1090 <frame@plt>
lea    0xc82(%rip),%rdi
call   1050 <printf@plt>
mov    0x2c2c(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x5f8,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
je     11e1 <main+0x21>
mov    (%rbx),%rdi
call   10c0 <usage@plt>
mov    0x8(%rbx),%rdi
lea    0xa(%rsp),%rsi
call   1080 <readmac@plt>
cmp    $0x1,%eax
jne    1352 <main+0x192>
mov    0x10(%rbx),%rdi
lea    0x4(%rsp),%rsi
call   1080 <readmac@plt>
cmp    $0x1,%eax
jne    1352 <main+0x192>
mov    0x2dd2(%rip),%r13
mov    0x0(%r13),%edi
call   10a0 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    136c <main+0x1ac>
xor    %ebp,%ebp
lea    0x10(%rsp),%r12
lea    0xa(%rsp),%r14
lea    0x4(%rsp),%r15
jmp    1293 <main+0xd3>
nopl   0x0(%rax)
paddd  %xmm1,%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%eax
movzbl 0x5e8(%rsp),%ecx
add    %eax,%ecx
movzbl 0x5e9(%rsp),%eax
add    %ecx,%eax
movzbl 0x5ea(%rsp),%ecx
add    %eax,%ecx
movzbl 0x5eb(%rsp),%ebp
add    %ecx,%ebp
mov    0x0(%r13),%edi
call   10a0 <feof@plt>
test   %eax,%eax
jne    136c <main+0x1ac>
mov    0x0(%r13),%ecx
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x5dc,%edx
call   1050 <fread@plt>
mov    %eax,%ebx
mov    0x0(%r13),%edi
call   1040 <ferror@plt>
test   %rax,%rax
jne    13cb <main+0x20b>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %r12,%rcx
call   1090 <frame@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movd   %ebp,%xmm3
pxor   %xmm2,%xmm2
mov    $0xc,%eax
pxor   %xmm4,%xmm4
nopl   0x0(%rax,%rax,1)
movdqa 0x4(%rsp,%rax,1),%xmm1
movd   0x8(%rsp,%rax,1),%xmm0
punpcklbw %xmm4,%xmm1
punpcklwd %xmm4,%xmm1
paddd  %xmm3,%xmm1
punpcklbw %xmm4,%xmm0
punpcklwd %xmm4,%xmm0
paddd  %xmm2,%xmm0
cmp    $0x5dc,%rax
je     1240 <main+0x80>
movq   0xc(%rsp,%rax,1),%xmm2
movd   0x10(%rsp,%rax,1),%xmm3
punpcklbw %xmm4,%xmm2
punpcklwd %xmm4,%xmm2
punpcklbw %xmm4,%xmm3
punpcklwd %xmm4,%xmm3
paddd  %xmm2,%xmm1
paddd  %xmm3,%xmm0
add    $0x10,%rax
movdqa %xmm1,%xmm3
movdqa %xmm0,%xmm2
jmp    12f0 <main+0x130>
lea    0xca7(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c73(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    %ebp,%edi
call   1060 <htonl@plt>
mov    %eax,(%rsp)
lea    0x10(%rsp),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   10b0 <memcpy@plt>
lea    0x14(%rsp),%rdi
xor    %esi,%esi
mov    $0x5d8,%edx
call   1070 <memset@plt>
lea    0xa(%rsp),%rdi
lea    0x4(%rsp),%rsi
mov    $0x5dc,%edx
mov    %rbx,%rcx
call   1090 <frame@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2c0c(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    0xc3d(%rip),%rdi
jmp    1359 <main+0x199>

LLVM IR (-O0):
@.str = [15 x i8] c"argument error\00"
@EXIT_FAILURE = global i32 0
@stdin = global i32 0
@.str.1 = [11 x i8] c"read error\00"
@.str.2 = [2 x i8] c"\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [1500 x i8]
%12 = alloca [6 x i8]
%13 = alloca [6 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @usage(i8* %19)
br label %21
21: ; preds = %16, %2
store i32 0, i32* %9
store i32 0, i32* %10
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 0
%26 = call i32 @readmac(i8* %24, i8* %25)
%27 = icmp ne i32 %26, 1
br i1 %27, label %35, label %28
28: ; preds = %21
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = getelementptr inbounds [6 x i8], [6 x i8]* %13, i64 0, i64 0
%33 = call i32 @readmac(i8* %31, i8* %32)
%34 = icmp ne i32 %33, 1
br i1 %34, label %35, label %39
35: ; preds = %28, %21
%36 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %28
br label %40
40: ; preds = %78, %39
%41 = load i32, i32* @stdin
%42 = call i32 @feof(i32 %41)
%43 = icmp ne i32 %42, 0
%44 = xor i1 %43, true
br i1 %44, label %45, label %82
45: ; preds = %40
%46 = getelementptr inbounds [1500 x i8], [1500 x i8]* %11, i64 0, i64 0
%47 = load i32, i32* @stdin
%48 = call i32 @fread(i8* %46, i32 1, i32 1500, i32 %47)
store i32 %48, i32* %6
%49 = load i32, i32* @stdin
%50 = call i64 @ferror(i32 %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %45
%53 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %45
%57 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 0
%58 = getelementptr inbounds [6 x i8], [6 x i8]* %13, i64 0, i64 0
%59 = load i32, i32* %6
%60 = getelementptr inbounds [1500 x i8], [1500 x i8]* %11, i64 0, i64 0
%61 = call i32 @frame(i8* %57, i8* %58, i32 %59, i8* %60)
%62 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %7
br label %63
63: ; preds = %75, %56
%64 = load i32, i32* %7
%65 = sext i32 %64 to i64
%66 = icmp ult i64 %65, 1500
br i1 %66, label %67, label %78
67: ; preds = %63
%68 = load i32, i32* %7
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [1500 x i8], [1500 x i8]* %11, i64 0, i64 %69
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = load i32, i32* %10
%74 = add nsw i32 %73, %72
store i32 %74, i32* %10
br label %75
75: ; preds = %67
%76 = load i32, i32* %7
%77 = add nsw i32 %76, 1
store i32 %77, i32* %7
br label %63
78: ; preds = %63
%79 = load i32, i32* %6
%80 = load i32, i32* %9
%81 = add nsw i32 %80, %79
store i32 %81, i32* %9
br label %40
82: ; preds = %40
%83 = load i32, i32* %10
%84 = call i32 @htonl(i32 %83)
store i32 %84, i32* %8
%85 = getelementptr inbounds [1500 x i8], [1500 x i8]* %11, i64 0, i64 0
%86 = call i32 @memcpy(i8* %85, i32* %8, i32 4)
%87 = getelementptr inbounds [1500 x i8], [1500 x i8]* %11, i64 0, i64 0
%88 = getelementptr inbounds i8, i8* %87, i64 4
%89 = call i32 @memset(i8* %88, i32 0, i32 1496)
%90 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 0
%91 = getelementptr inbounds [6 x i8], [6 x i8]* %13, i64 0, i64 0
%92 = getelementptr inbounds [1500 x i8], [1500 x i8]* %11, i64 0, i64 0
%93 = call i32 @frame(i8* %90, i8* %91, i32 1500, i8* %92)
%94 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%95 = load i32, i32* @EXIT_SUCCESS
%96 = call i32 @exit(i32 %95)
unreachable
}

LLVM IR (-O2):
@.str = [15 x i8] c"argument error\00"
@EXIT_FAILURE = global i32 0
@stdin = global i32 0
@.str.1 = [11 x i8] c"read error\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [1500 x i8]
%5 = alloca [6 x i8]
%6 = alloca [6 x i8]
%7 = icmp eq i32 %0, 3
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 @usage(i8* %9)
br label %11
11: ; preds = %8, %2
%12 = bitcast i32* %3 to i8*
%13 = getelementptr inbounds [1500 x i8], [1500 x i8]* %4, i64 0, i64 0
%14 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%15 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @readmac(i8* %17, i8* %14)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %34
20: ; preds = %11
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @readmac(i8* %22, i8* %15)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %34
25: ; preds = %20
%26 = load i32, i32* @stdin
%27 = call i32 @feof(i32 %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %99
29: ; preds = %25
%30 = getelementptr inbounds [1500 x i8], [1500 x i8]* %4, i64 0, i64 1496
%31 = getelementptr inbounds [1500 x i8], [1500 x i8]* %4, i64 0, i64 1497
%32 = getelementptr inbounds [1500 x i8], [1500 x i8]* %4, i64 0, i64 1498
%33 = getelementptr inbounds [1500 x i8], [1500 x i8]* %4, i64 0, i64 1499
br label %38
34: ; preds = %20, %11
%35 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %29, %81
%39 = phi i32 [ %95, %81 ], [ 0, %29 ]
%40 = load i32, i32* @stdin
%41 = call i32 @fread(i8* %13, i32 1, i32 1500, i32 %40)
%42 = load i32, i32* @stdin
%43 = call i64 @ferror(i32 %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %49, label %45
45: ; preds = %38
%46 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %38
%50 = call i32 @frame(i8* %14, i8* %15, i32 %41, i8* %13)
%51 = call i32 @putchar(i32 10)
%52 = insertelement <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, i32 %39, i64 0
br label %53
53: ; preds = %69, %49
%54 = phi i64 [ 0, %49 ], [ %80, %69 ]
%55 = phi <4 x i32> [ %52, %49 ], [ %78, %69 ]
%56 = phi <4 x i32> [ zeroinitializer, %49 ], [ %79, %69 ]
%57 = getelementptr inbounds [1500 x i8], [1500 x i8]* %4, i64 0, i64 %54
%58 = bitcast i8* %57 to <4 x i8>*
%59 = load <4 x i8>, <4 x i8>* %58
%60 = getelementptr inbounds i8, i8* %57, i64 4
%61 = bitcast i8* %60 to <4 x i8>*
%62 = load <4 x i8>, <4 x i8>* %61
%63 = zext <4 x i8> %59 to <4 x i32>
%64 = zext <4 x i8> %62 to <4 x i32>
%65 = add <4 x i32> %55, %63
%66 = add <4 x i32> %56, %64
%67 = or i64 %54, 8
%68 = icmp eq i64 %67, 1496
br i1 %68, label %81, label %69
69: ; preds = %53
%70 = getelementptr inbounds [1500 x i8], [1500 x i8]* %4, i64 0, i64 %67
%71 = bitcast i8* %70 to <4 x i8>*
%72 = load <4 x i8>, <4 x i8>* %71
%73 = getelementptr inbounds i8, i8* %70, i64 4
%74 = bitcast i8* %73 to <4 x i8>*
%75 = load <4 x i8>, <4 x i8>* %74
%76 = zext <4 x i8> %72 to <4 x i32>
%77 = zext <4 x i8> %75 to <4 x i32>
%78 = add <4 x i32> %65, %76
%79 = add <4 x i32> %66, %77
%80 = add nuw nsw i64 %54, 16
br label %53
81: ; preds = %53
%82 = add <4 x i32> %66, %65
%83 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %82)
%84 = load i8, i8* %30
%85 = zext i8 %84 to i32
%86 = add nsw i32 %83, %85
%87 = load i8, i8* %31
%88 = zext i8 %87 to i32
%89 = add nsw i32 %86, %88
%90 = load i8, i8* %32
%91 = zext i8 %90 to i32
%92 = add nsw i32 %89, %91
%93 = load i8, i8* %33
%94 = zext i8 %93 to i32
%95 = add nsw i32 %92, %94
%96 = load i32, i32* @stdin
%97 = call i32 @feof(i32 %96)
%98 = icmp eq i32 %97, 0
br i1 %98, label %38, label %99
99: ; preds = %81, %25
%100 = phi i32 [ 0, %25 ], [ %95, %81 ]
%101 = call i32 @htonl(i32 %100)
store i32 %101, i32* %3
%102 = call i32 @memcpy(i8* %13, i32* %3, i32 4)
%103 = getelementptr inbounds [1500 x i8], [1500 x i8]* %4, i64 0, i64 4
%104 = call i32 @memset(i8* %103, i32 0, i32 1496)
%105 = call i32 @frame(i8* %14, i8* %15, i32 1500, i8* %13)
%106 = call i32 @putchar(i32 10)
%107 = load i32, i32* @EXIT_SUCCESS
%108 = call i32 @exit(i32 %107)
unreachable
}