#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 uint32_t;

/* Variables and functions */
int atoi(char const *);
int parse_mac(char const *, unsigned char *);
int /*<<< orphan*/ print_mac(unsigned char *);
int /*<<< orphan*/ usage();
int maccalc_do_add(int argc, const char *argv[]) {
  unsigned char mac[6];
  uint32_t t;
  int err;
  int i;
  if (argc != 2) {
    usage();
    return 1;
  }
  err = parse_mac(argv[0], mac);
  if (err)
    return err;
  i = atoi(argv[1]);
  t = (mac[3] << 16) | (mac[4] << 8) | mac[5];
  t += i;
  mac[3] = (t >> 16) & 0xff;
  mac[4] = (t >> 8) & 0xff;
  mac[5] = t & 0xff;
  print_mac(mac);
  return 0;
}


x86 assembly (clang, -O0):
<maccalc_do_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     116c <maccalc_do_add+0x2c>
mov    $0x0,%al
call   1050 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fd <maccalc_do_add+0xbd>
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_add+0x54>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fd <maccalc_do_add+0xbd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
movzbl -0x13(%rbp),%eax
shl    $0x10,%eax
movzbl -0x12(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movzbl -0x11(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,-0x13(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x12(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x11(%rbp)
lea    -0x16(%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_add>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11a1 <maccalc_do_add+0x61>
mov    %rsi,%rbx
mov    (%rsi),%rdi
lea    0xa(%rsp),%rsi
call   1040 <parse_mac@plt>
test   %eax,%eax
jne    11ad <maccalc_do_add+0x6d>
mov    0x8(%rbx),%rdi
call   1060 <atoi@plt>
movzbl 0xd(%rsp),%ecx
shl    $0x10,%ecx
movzbl 0xe(%rsp),%edx
shl    $0x8,%edx
or     %ecx,%edx
movzbl 0xf(%rsp),%ecx
or     %edx,%ecx
add    %eax,%ecx
mov    %ecx,%eax
shr    $0x10,%eax
mov    %al,0xd(%rsp)
mov    %ch,0xe(%rsp)
mov    %cl,0xf(%rsp)
lea    0xa(%rsp),%rdi
call   1030 <print_mac@plt>
xor    %eax,%eax
jmp    11ad <maccalc_do_add+0x6d>
xor    %eax,%eax
call   1050 <usage@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @maccalc_do_add(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, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (...) @usage()
br label %36
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 %36
12: ; preds = %8
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 3
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = shl nuw nsw i32 %18, 16
%20 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 4
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = shl nuw nsw i32 %22, 8
%24 = or i32 %23, %19
%25 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 5
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = or i32 %24, %27
%29 = add nsw i32 %28, %15
%30 = lshr i32 %29, 16
%31 = trunc i32 %30 to i8
store i8 %31, i8* %16
%32 = lshr i32 %29, 8
%33 = trunc i32 %32 to i8
store i8 %33, i8* %20
%34 = trunc i32 %29 to i8
store i8 %34, i8* %25
%35 = call i32 @print_mac(i8* %4)
br label %36
36: ; preds = %8, %12, %6
%37 = phi i32 [ 1, %6 ], [ 0, %12 ], [ %10, %8 ]
ret i32 %37
}