#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*/ uint8_t;
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int send_exact_entry(int /*<<< orphan*/, int /*<<< orphan*/ *, char *, char *,
                     char *, char *, int /*<<< orphan*/);
int sscanf(char const *, char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int process_mac_fwd(const char *line) {
  uint16_t port;
  uint8_t mac[6];
  int matches = sscanf(line, "%*s %hhx:%hhx:%hhx:%hhx:%hhx:%hhx %hd", &mac[0],
                       &mac[1], &mac[2], &mac[3], &mac[4], &mac[5], &port);
  if (7 != matches)
    return -1;
  send_exact_entry(port, mac, "dmac", "ethernet.dstAddr", "forward", "port", 0);
  return send_exact_entry(port, mac, "smac", "ethernet.srcAddr", "_nop", 0, 0);
}


x86 assembly (clang, -O0):
<process_mac_fwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    -0x30(%rbp),%rcx
add    $0x4,%rcx
lea    -0x30(%rbp),%r8
add    $0x8,%r8
lea    -0x30(%rbp),%r9
add    $0xc,%r9
lea    -0x30(%rbp),%r11
add    $0x10,%r11
lea    -0x30(%rbp),%r10
add    $0x14,%r10
lea    0xe9d(%rip),%rsi
lea    -0x14(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1030 <sscanf@plt>
mov    %eax,-0x34(%rbp)
mov    $0x7,%eax
cmp    -0x34(%rbp),%eax
je     1197 <process_mac_fwd+0x77>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fa <process_mac_fwd+0xda>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    0xe81(%rip),%rdx
lea    0xe7f(%rip),%rcx
lea    0xe89(%rip),%r8
lea    0xe8a(%rip),%r9
xor    %eax,%eax
movl   $0x0,(%rsp)
call   1040 <send_exact_entry@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    0xe73(%rip),%rdx
lea    0xe71(%rip),%rcx
lea    0xe7b(%rip),%r8
xor    %eax,%eax
mov    %eax,%r9d
xor    %eax,%eax
movl   $0x0,(%rsp)
call   1040 <send_exact_entry@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_mac_fwd>:
push   %rbx
sub    $0x40,%rsp
lea    0x24(%rsp),%rcx
lea    0x28(%rsp),%r8
lea    0x2c(%rsp),%r9
lea    0x30(%rsp),%rax
lea    0x34(%rsp),%rdx
lea    0x1c(%rsp),%rsi
mov    %rsi,0x10(%rsp)
mov    %rdx,0x8(%rsp)
mov    %rax,(%rsp)
lea    0xea8(%rip),%rsi
lea    0x20(%rsp),%rdx
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x7,%ecx
jne    11cd <process_mac_fwd+0xad>
mov    0x1c(%rsp),%edi
movl   $0x0,(%rsp)
lea    0xea6(%rip),%rdx
lea    0xea4(%rip),%rcx
lea    0xeae(%rip),%r8
lea    0xeaf(%rip),%r9
lea    0x20(%rsp),%rbx
mov    %rbx,%rsi
call   1040 <send_exact_entry@plt>
mov    0x1c(%rsp),%edi
movl   $0x0,(%rsp)
lea    0xe95(%rip),%rdx
lea    0xe93(%rip),%rcx
lea    0xe9d(%rip),%r8
mov    %rbx,%rsi
xor    %r9d,%r9d
call   1040 <send_exact_entry@plt>
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [38 x i8] c"%*s %hhx:%hhx:%hhx:%hhx:%hhx:%hhx %hd\00"
@.str.1 = [5 x i8] c"dmac\00"
@.str.2 = [17 x i8] c"ethernet.dstAddr\00"
@.str.3 = [8 x i8] c"forward\00"
@.str.4 = [5 x i8] c"port\00"
@.str.5 = [5 x i8] c"smac\00"
@.str.6 = [17 x i8] c"ethernet.srcAddr\00"
@.str.7 = [5 x i8] c"_nop\00"
define i32 @process_mac_fwd(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [6 x i32]
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 0
%9 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 1
%10 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 2
%11 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 3
%12 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 4
%13 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 5
%14 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32* %8, i32* %9, i32* %10, i32* %11, i32* %12, i32* %13, i32* %4)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp ne i32 7, %15
br i1 %16, label %17, label %18
17: ; preds = %1
store i32 -1, i32* %2
br label %25
18: ; preds = %1
%19 = load i32, i32* %4
%20 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 0
%21 = call i32 @send_exact_entry(i32 %19, i32* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 0)
%22 = load i32, i32* %4
%23 = getelementptr inbounds [6 x i32], [6 x i32]* %5, i64 0, i64 0
%24 = call i32 @send_exact_entry(i32 %22, i32* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* null, i32 0)
store i32 %24, i32* %2
br label %25
25: ; preds = %18, %17
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [38 x i8] c"%*s %hhx:%hhx:%hhx:%hhx:%hhx:%hhx %hd\00"
@.str.1 = [5 x i8] c"dmac\00"
@.str.2 = [17 x i8] c"ethernet.dstAddr\00"
@.str.3 = [8 x i8] c"forward\00"
@.str.4 = [5 x i8] c"port\00"
@.str.5 = [5 x i8] c"smac\00"
@.str.6 = [17 x i8] c"ethernet.srcAddr\00"
@.str.7 = [5 x i8] c"_nop\00"
define i32 @process_mac_fwd(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca [6 x i32]
%4 = bitcast i32* %2 to i8*
%5 = bitcast [6 x i32]* %3 to i8*
%6 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%7 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 1
%8 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 2
%9 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 3
%10 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 4
%11 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 5
%12 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32* %11, i32* %2)
%13 = icmp eq i32 %12, 7
br i1 %13, label %14, label %19
14: ; preds = %1
%15 = load i32, i32* %2
%16 = call i32 @send_exact_entry(i32 %15, i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 0)
%17 = load i32, i32* %2
%18 = call i32 @send_exact_entry(i32 %17, i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* null, i32 0)
br label %19
19: ; preds = %1, %14
%20 = phi i32 [ %18, %14 ], [ -1, %1 ]
ret i32 %20
}