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

/* Variables and functions */
int netgroup_match(char const *, char const *, char *);
int /*<<< orphan*/ resolve_hostname(char const *);
scalar_t__ strcasecmp(char const *, char const *);
scalar_t__ strchr(char const *, char);
scalar_t__ string_match(char const *, char const *);
int strlen(char const *);
scalar_t__ strncmp(char const *, int /*<<< orphan*/, int);
int from_match(const char *tok, const char *string) {
  int tok_len;
  int str_len;
  if (tok[0] == '@') {
    return (netgroup_match(tok + 1, string, (char *)0));
  } else if (string_match(tok, string)) {
    return (1);
  } else if (tok[0] == '.') {
    if ((str_len = strlen(string)) > (tok_len = strlen(tok)) &&
        strcasecmp(tok, string + str_len - tok_len) == 0)
      return (1);
  } else if (strcasecmp(tok, "LOCAL") == 0) {
    if (strchr(string, '.') == 0)
      return (1);
  } else if (tok[(tok_len = strlen(tok)) - 1] == '.' &&
             strncmp(tok, resolve_hostname(string), tok_len) == 0) {
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<from_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
jne    11ad <from_match+0x3d>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <netgroup_match@plt>
mov    %eax,-0x4(%rbp)
jmp    1303 <from_match+0x193>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <string_match@plt>
cmp    $0x0,%rax
je     11d0 <from_match+0x60>
movl   $0x1,-0x4(%rbp)
jmp    1303 <from_match+0x193>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1243 <from_match+0xd3>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
mov    %ecx,-0x1c(%rbp)
cmp    %ecx,%eax
jle    123e <from_match+0xce>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
movslq -0x1c(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    123e <from_match+0xce>
movl   $0x1,-0x4(%rbp)
jmp    1303 <from_match+0x193>
jmp    12f2 <from_match+0x182>
mov    -0x10(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1286 <from_match+0x116>
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
jne    1281 <from_match+0x111>
movl   $0x1,-0x4(%rbp)
jmp    1303 <from_match+0x193>
jmp    12ed <from_match+0x17d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,-0x1c(%rbp)
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    12e8 <from_match+0x178>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <resolve_hostname@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
mov    -0x1c(%rbp),%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12e8 <from_match+0x178>
movl   $0x1,-0x4(%rbp)
jmp    1303 <from_match+0x193>
jmp    12ed <from_match+0x17d>
jmp    12f2 <from_match+0x182>
jmp    12f7 <from_match+0x187>
jmp    12fc <from_match+0x18c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<from_match>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rbp
cmpb   $0x40,(%rdi)
jne    119d <from_match+0x2d>
add    $0x1,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <netgroup_match@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1090 <string_match@plt>
mov    $0x1,%r14d
test   %rax,%rax
jne    1241 <from_match+0xd1>
cmpb   $0x2e,0x0(%rbp)
jne    11ed <from_match+0x7d>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1050 <strlen@plt>
cmp    %eax,%r15d
jle    123e <from_match+0xce>
movslq %r15d,%rcx
add    %rcx,%rbx
cltq
sub    %rax,%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcasecmp@plt>
jmp    1239 <from_match+0xc9>
lea    0xe0c(%rip),%rsi
mov    %rbp,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     122c <from_match+0xbc>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
cltq
cmpb   $0x2e,-0x1(%rax,%rbp,1)
jne    123e <from_match+0xce>
mov    %rbx,%rdi
call   1080 <resolve_hostname@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    %r15d,%edx
call   1040 <strncmp@plt>
jmp    1239 <from_match+0xc9>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1241 <from_match+0xd1>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"LOCAL\00"
define i32 @from_match(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 64
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8*, i8** %5
%17 = call i32 @netgroup_match(i8* %15, i8* %16, i8* null)
store i32 %17, i32* %3
br label %83
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = call i64 @string_match(i8* %19, i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 1, i32* %3
br label %83
24: ; preds = %18
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 46
br i1 %29, label %30, label %50
30: ; preds = %24
%31 = load i8*, i8** %5
%32 = call i32 @strlen(i8* %31)
store i32 %32, i32* %7
%33 = load i8*, i8** %4
%34 = call i32 @strlen(i8* %33)
store i32 %34, i32* %6
%35 = icmp sgt i32 %32, %34
br i1 %35, label %36, label %49
36: ; preds = %30
%37 = load i8*, i8** %4
%38 = load i8*, i8** %5
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = sub i64 0, %43
%45 = getelementptr inbounds i8, i8* %41, i64 %44
%46 = call i64 @strcasecmp(i8* %37, i8* %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %36
store i32 1, i32* %3
br label %83
49: ; preds = %36, %30
br label %80
50: ; preds = %24
%51 = load i8*, i8** %4
%52 = call i64 @strcasecmp(i8* %51, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %60
54: ; preds = %50
%55 = load i8*, i8** %5
%56 = call i64 @strchr(i8* %55, i8 signext 46)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %54
store i32 1, i32* %3
br label %83
59: ; preds = %54
br label %79
60: ; preds = %50
%61 = load i8*, i8** %4
%62 = load i8*, i8** %4
%63 = call i32 @strlen(i8* %62)
store i32 %63, i32* %6
%64 = sub nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %61, i64 %65
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 46
br i1 %69, label %70, label %78
70: ; preds = %60
%71 = load i8*, i8** %4
%72 = load i8*, i8** %5
%73 = call i32 @resolve_hostname(i8* %72)
%74 = load i32, i32* %6
%75 = call i64 @strncmp(i8* %71, i32 %73, i32 %74)
%76 = icmp eq i64 %75, 0
br i1 %76, label %77, label %78
77: ; preds = %70
store i32 1, i32* %3
br label %83
78: ; preds = %70, %60
br label %79
79: ; preds = %78, %59
br label %80
80: ; preds = %79, %49
br label %81
81: ; preds = %80
br label %82
82: ; preds = %81
store i32 0, i32* %3
br label %83
83: ; preds = %82, %77, %58, %48, %23, %13
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@.str = [6 x i8] c"LOCAL\00"
define i32 @from_match(i8* %0, i8* %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 64
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = tail call i32 @netgroup_match(i8* %6, i8* %1, i8* null)
br label %44
8: ; preds = %2
%9 = tail call i64 @string_match(i8* %0, i8* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %44
11: ; preds = %8
%12 = load i8, i8* %0
%13 = icmp eq i8 %12, 46
br i1 %13, label %14, label %26
14: ; preds = %11
%15 = tail call i32 @strlen(i8* %1)
%16 = tail call i32 @strlen(i8* %0)
%17 = icmp sgt i32 %15, %16
br i1 %17, label %18, label %43
18: ; preds = %14
%19 = sext i32 %15 to i64
%20 = getelementptr inbounds i8, i8* %1, i64 %19
%21 = sext i32 %16 to i64
%22 = sub nsw i64 0, %21
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = tail call i64 @strcasecmp(i8* %0, i8* %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %44, label %43
26: ; preds = %11
%27 = tail call i64 @strcasecmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = tail call i64 @strchr(i8* %1, i8 signext 46)
%31 = icmp eq i64 %30, 0
br i1 %31, label %44, label %43
32: ; preds = %26
%33 = tail call i32 @strlen(i8* %0)
%34 = add nsw i32 %33, -1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %0, i64 %35
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 46
br i1 %38, label %39, label %43
39: ; preds = %32
%40 = tail call i32 @resolve_hostname(i8* %1)
%41 = tail call i64 @strncmp(i8* %0, i32 %40, i32 %33)
%42 = icmp eq i64 %41, 0
br i1 %42, label %44, label %43
43: ; preds = %29, %39, %32, %14, %18
br label %44
44: ; preds = %39, %29, %18, %8, %43, %5
%45 = phi i32 [ %7, %5 ], [ 0, %43 ], [ 1, %8 ], [ 1, %18 ], [ 1, %29 ], [ 1, %39 ]
ret i32 %45
}