#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 */
struct in_addr {
  int /*<<< orphan*/ s_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int ETH_ALEN;
int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int inet_pton(int /*<<< orphan*/, char *, struct in_addr *);
int /*<<< orphan*/ loop(int, int /*<<< orphan*/, char *, int /*<<< orphan*/,
                        char *);
int sscanf(char *, char *, char *, char *, char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int ifindex = 0;
  struct in_addr sip, tip;
  char sha[ETH_ALEN], tha[ETH_ALEN];
  if (argc != 6) {
    fprintf(stderr, "%s ifindex sip sha tip tha\n", argv[0]);
    return -1;
  }
  ifindex = atoi(argv[1]);
  if (inet_pton(AF_INET, argv[2], &sip) != 1) {
    fprintf(stderr, "invalid sip\n");
    return -1;
  }
  if (sscanf(argv[3], "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", &sha[0],
             &sha[1], &sha[2], &sha[3], &sha[4], &sha[5]) != 6) {
    fprintf(stderr, "invalid sha\n");
    return -1;
  }
  if (inet_pton(AF_INET, argv[4], &tip) != 1) {
    fprintf(stderr, "invalid tip\n");
    return -1;
  }
  if (sscanf(argv[5], "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", &tha[0],
             &tha[1], &tha[2], &tha[3], &tha[4], &tha[5]) != 6) {
    fprintf(stderr, "invalid tha\n");
    return -1;
  }
  loop(ifindex, sip.s_addr, sha, tip.s_addr, tha);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x28(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x30(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
cmpl   $0x6,-0x8(%rbp)
je     11f2 <main+0xa2>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    13be <main+0x26e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <inet_pton@plt>
cmp    $0x1,%eax
je     124f <main+0xff>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
lea    0xde7(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    13be <main+0x26e>
mov    -0x50(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    %rdx,%rcx
add    $0x1,%rcx
mov    %rdx,%r8
add    $0x2,%r8
mov    %rdx,%r9
add    $0x3,%r9
mov    %rdx,%r10
add    $0x4,%r10
mov    %rdx,%rax
add    $0x5,%rax
lea    0xda4(%rip),%rsi
sub    $0x10,%rsp
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1060 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x6,%eax
je     12ce <main+0x17e>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
lea    0xd9f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    13be <main+0x26e>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <inet_pton@plt>
cmp    $0x1,%eax
je     131b <main+0x1cb>
mov    0x2cd8(%rip),%rax
mov    (%rax),%edi
lea    0xd5f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    13be <main+0x26e>
mov    -0x48(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
mov    %rdx,%rcx
add    $0x1,%rcx
mov    %rdx,%r8
add    $0x2,%r8
mov    %rdx,%r9
add    $0x3,%r9
mov    %rdx,%r10
add    $0x4,%r10
mov    %rdx,%rax
add    $0x5,%rax
lea    0xcd8(%rip),%rsi
sub    $0x10,%rsp
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1060 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x6,%eax
je     139a <main+0x24a>
mov    0x2c59(%rip),%rax
mov    (%rax),%edi
lea    0xced(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    13be <main+0x26e>
mov    -0x48(%rbp),%r8
mov    -0x50(%rbp),%rdx
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%ecx
call   1030 <loop@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rsp,%r13
mov    0x2e72(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
cmp    $0x6,%edi
jne    126d <main+0x11d>
mov    0x8(%r15),%rdi
call   1070 <atoi@plt>
mov    %eax,%r12d
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r15),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <inet_pton@plt>
cmp    $0x1,%eax
jne    1289 <main+0x139>
mov    %r12d,-0x3c(%rbp)
mov    0x18(%r15),%rdi
lea    0x1(%rbx),%rcx
lea    0x2(%rbx),%r8
lea    0x3(%rbx),%r9
lea    0x4(%rbx),%r10
lea    0x5(%rbx),%rax
lea    0xe3e(%rip),%rsi
mov    %rbx,%rdx
push   %rax
push   %r10
call   1060 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x6,%eax
jne    129b <main+0x14b>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    0x20(%r15),%rsi
lea    -0x30(%rbp),%rdx
call   1050 <inet_pton@plt>
cmp    $0x1,%eax
jne    12ad <main+0x15d>
mov    0x28(%r15),%rdi
lea    0x1(%r14),%rcx
lea    0x2(%r14),%r8
lea    0x3(%r14),%r9
lea    0x4(%r14),%r10
lea    0x5(%r14),%rax
lea    0xde8(%rip),%rsi
mov    %r14,%rdx
push   %rax
push   %r10
call   1060 <sscanf@plt>
add    $0x10,%rsp
cmp    $0x6,%eax
jne    12bf <main+0x16f>
mov    -0x38(%rbp),%esi
mov    -0x30(%rbp),%ecx
mov    -0x3c(%rbp),%edi
mov    %rbx,%rdx
mov    %r14,%r8
call   1030 <loop@plt>
xor    %eax,%eax
jmp    12db <main+0x18b>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xd80(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    12d6 <main+0x186>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
lea    0xd83(%rip),%rsi
jmp    12cf <main+0x17f>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
lea    0xda8(%rip),%rsi
jmp    12cf <main+0x17f>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
lea    0xda3(%rip),%rsi
jmp    12cf <main+0x17f>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
lea    0xd9e(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@ETH_ALEN = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"%s ifindex sip sha tip tha\0A\00"
@AF_INET = global i32 0
@.str.1 = [13 x i8] c"invalid sip\0A\00"
@.str.2 = [42 x i8] c"%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\00"
@.str.3 = [13 x i8] c"invalid sha\0A\00"
@.str.4 = [13 x i8] c"invalid tip\0A\00"
@.str.5 = [13 x i8] c"invalid tha\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.in_addr
%8 = alloca %struct.in_addr
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%13 = load i32, i32* @ETH_ALEN
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %9
%16 = alloca i8, i64 %14
store i64 %14, i64* %10
%17 = load i32, i32* @ETH_ALEN
%18 = zext i32 %17 to i64
%19 = alloca i8, i64 %18
store i64 %18, i64* %11
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 6
br i1 %21, label %22, label %28
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %26)
store i32 -1, i32* %3
store i32 1, i32* %12
br label %89
28: ; preds = %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %6
%33 = load i32, i32* @AF_INET
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i32 @inet_pton(i32 %33, i8* %36, %struct.in_addr* %7)
%38 = icmp ne i32 %37, 1
br i1 %38, label %39, label %42
39: ; preds = %28
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %12
br label %89
42: ; preds = %28
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 3
%45 = load i8*, i8** %44
%46 = getelementptr inbounds i8, i8* %16, i64 0
%47 = getelementptr inbounds i8, i8* %16, i64 1
%48 = getelementptr inbounds i8, i8* %16, i64 2
%49 = getelementptr inbounds i8, i8* %16, i64 3
%50 = getelementptr inbounds i8, i8* %16, i64 4
%51 = getelementptr inbounds i8, i8* %16, i64 5
%52 = call i32 @sscanf(i8* %45, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %46, i8* %47, i8* %48, i8* %49, i8* %50, i8* %51)
%53 = icmp ne i32 %52, 6
br i1 %53, label %54, label %57
54: ; preds = %42
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %12
br label %89
57: ; preds = %42
%58 = load i32, i32* @AF_INET
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 4
%61 = load i8*, i8** %60
%62 = call i32 @inet_pton(i32 %58, i8* %61, %struct.in_addr* %8)
%63 = icmp ne i32 %62, 1
br i1 %63, label %64, label %67
64: ; preds = %57
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %12
br label %89
67: ; preds = %57
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 5
%70 = load i8*, i8** %69
%71 = getelementptr inbounds i8, i8* %19, i64 0
%72 = getelementptr inbounds i8, i8* %19, i64 1
%73 = getelementptr inbounds i8, i8* %19, i64 2
%74 = getelementptr inbounds i8, i8* %19, i64 3
%75 = getelementptr inbounds i8, i8* %19, i64 4
%76 = getelementptr inbounds i8, i8* %19, i64 5
%77 = call i32 @sscanf(i8* %70, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %71, i8* %72, i8* %73, i8* %74, i8* %75, i8* %76)
%78 = icmp ne i32 %77, 6
br i1 %78, label %79, label %82
79: ; preds = %67
%80 = load i32, i32* @stderr
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %12
br label %89
82: ; preds = %67
%83 = load i32, i32* %6
%84 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %7, i32 0, i32 0
%85 = load i32, i32* %84
%86 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i32 0, i32 0
%87 = load i32, i32* %86
%88 = call i32 @loop(i32 %83, i32 %85, i8* %16, i32 %87, i8* %19)
store i32 0, i32* %3
store i32 1, i32* %12
br label %89
89: ; preds = %82, %79, %64, %54, %39, %22
%90 = load i8*, i8** %9
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@ETH_ALEN = global i32 0
@stderr = global i32 0
@.str = [28 x i8] c"%s ifindex sip sha tip tha\0A\00"
@AF_INET = global i32 0
@.str.1 = [13 x i8] c"invalid sip\0A\00"
@.str.2 = [42 x i8] c"%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\00"
@.str.3 = [13 x i8] c"invalid sha\0A\00"
@.str.4 = [13 x i8] c"invalid tip\0A\00"
@.str.5 = [13 x i8] c"invalid tha\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.in_addr
%4 = alloca %struct.in_addr
%5 = bitcast %struct.in_addr* %3 to i8*
%6 = bitcast %struct.in_addr* %4 to i8*
%7 = load i32, i32* @ETH_ALEN
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = load i32, i32* @ETH_ALEN
%12 = zext i32 %11 to i64
%13 = alloca i8, i64 %12
%14 = icmp eq i32 %0, 6
br i1 %14, label %19, label %15
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %1
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %72
19: ; preds = %2
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @inet_pton(i32 %23, i8* %25, %struct.in_addr* %3)
%27 = icmp eq i32 %26, 1
br i1 %27, label %31, label %28
28: ; preds = %19
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %72
31: ; preds = %19
%32 = getelementptr inbounds i8*, i8** %1, i64 3
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8, i8* %10, i64 1
%35 = getelementptr inbounds i8, i8* %10, i64 2
%36 = getelementptr inbounds i8, i8* %10, i64 3
%37 = getelementptr inbounds i8, i8* %10, i64 4
%38 = getelementptr inbounds i8, i8* %10, i64 5
%39 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %10, i8* %34, i8* %35, i8* %36, i8* %37, i8* %38)
%40 = icmp eq i32 %39, 6
br i1 %40, label %44, label %41
41: ; preds = %31
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %72
44: ; preds = %31
%45 = load i32, i32* @AF_INET
%46 = getelementptr inbounds i8*, i8** %1, i64 4
%47 = load i8*, i8** %46
%48 = call i32 @inet_pton(i32 %45, i8* %47, %struct.in_addr* %4)
%49 = icmp eq i32 %48, 1
br i1 %49, label %53, label %50
50: ; preds = %44
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %72
53: ; preds = %44
%54 = getelementptr inbounds i8*, i8** %1, i64 5
%55 = load i8*, i8** %54
%56 = getelementptr inbounds i8, i8* %13, i64 1
%57 = getelementptr inbounds i8, i8* %13, i64 2
%58 = getelementptr inbounds i8, i8* %13, i64 3
%59 = getelementptr inbounds i8, i8* %13, i64 4
%60 = getelementptr inbounds i8, i8* %13, i64 5
%61 = call i32 @sscanf(i8* %55, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %13, i8* %56, i8* %57, i8* %58, i8* %59, i8* %60)
%62 = icmp eq i32 %61, 6
br i1 %62, label %66, label %63
63: ; preds = %53
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %72
66: ; preds = %53
%67 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 0, i32 0
%68 = load i32, i32* %67
%69 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i64 0, i32 0
%70 = load i32, i32* %69
%71 = call i32 @loop(i32 %22, i32 %68, i8* %10, i32 %70, i8* %13)
br label %72
72: ; preds = %66, %63, %50, %41, %28, %15
%73 = phi i32 [ -1, %15 ], [ -1, %28 ], [ -1, %41 ], [ -1, %50 ], [ -1, %63 ], [ 0, %66 ]
ret i32 %73
}