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

/* Variables and functions */
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ get_domain(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ strncmp(char *, char *, int);
int main(int argc, char **argv) {
  FILE *list;
  char rule[254 + 3];
  char domain[254] = {0};
  if (argc > 2) {
    fputs("usage: hostsblock file\n", stderr);
    return 1;
  }
  if (argc < 2 || !strncmp(argv[1], "-", 2))
    list = stdin;
  else
    list = fopen(argv[1], "r");
  if (list == NULL) {
    perror("error opening filter list");
    return 1;
  }
  while (1) {
    char *c = fgets(rule, 254 + 3, list);
    if (c == NULL || feof(list) || ferror(list))
      break;
    if (!get_domain(rule, domain)) {
      printf("0\t%s\n", domain);
    }
  }
  if (ferror(list)) {
    perror("error reading filter list");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0xfe,%edx
call   1080 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
jle    11f7 <main+0x57>
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
lea    0xe1a(%rip),%rdi
call   1070 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    1331 <main+0x191>
cmpl   $0x2,-0x8(%rbp)
jl     1223 <main+0x83>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe08(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1236 <main+0x96>
mov    0x2dbe(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    124e <main+0xae>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd5(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1271 <main+0xd1>
lea    0xdbc(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1331 <main+0x191>
jmp    1276 <main+0xd6>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x101,%esi
call   1090 <fgets@plt>
mov    %rax,-0x228(%rbp)
cmpq   $0x0,-0x228(%rbp)
je     12c6 <main+0x126>
mov    -0x18(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%rax
jne    12c6 <main+0x126>
mov    -0x18(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     12cb <main+0x12b>
jmp    12ff <main+0x15f>
lea    -0x120(%rbp),%rdi
lea    -0x220(%rbp),%rsi
call   1060 <get_domain@plt>
cmp    $0x0,%eax
jne    12fa <main+0x15a>
lea    -0x220(%rbp),%rsi
lea    0xd41(%rip),%rdi
call   1050 <printf@plt>
jmp    1276 <main+0xd6>
mov    -0x18(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     132a <main+0x18a>
lea    0xd23(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1331 <main+0x191>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x208,%rsp
xorps  %xmm0,%xmm0
movups %xmm0,0xee(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
cmp    $0x3,%edi
jl     122c <main+0x9c>
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
lea    0xde3(%rip),%rdi
call   1070 <fputs@plt>
mov    $0x1,%eax
jmp    130d <main+0x17d>
cmp    $0x2,%edi
jne    1271 <main+0xe1>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xdd9(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1271 <main+0xe1>
mov    0x8(%rbx),%rdi
lea    0xdc2(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
test   %rbx,%rbx
jne    1280 <main+0xf0>
lea    0xdb0(%rip),%rdi
jmp    1323 <main+0x193>
mov    0x2d70(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
je     1265 <main+0xd5>
lea    0x100(%rsp),%rdi
mov    $0x101,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12fb <main+0x16b>
lea    0x100(%rsp),%r14
mov    %rsp,%r15
lea    0xd8a(%rip),%r12
jmp    12c5 <main+0x135>
xchg   %ax,%ax
mov    %r14,%rdi
mov    $0x101,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12fb <main+0x16b>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %rax,%rax
jne    12fb <main+0x16b>
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    12fb <main+0x16b>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <get_domain@plt>
test   %eax,%eax
jne    12b0 <main+0x120>
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
jmp    12b0 <main+0x120>
mov    %rbx,%rdi
call   1040 <ferror@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    131c <main+0x18c>
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd19(%rip),%rdi
call   10b0 <perror@plt>
jmp    1222 <main+0x92>

LLVM IR (-O0):
@.str = [24 x i8] c"usage: hostsblock file\0A\00"
@stderr = global i32 0
@.str.1 = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [26 x i8] c"error opening filter list\00"
@.str.4 = [6 x i8] c"0\09%s\0A\00"
@.str.5 = [26 x i8] c"error reading filter list\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [257 x i8]
%8 = alloca [254 x i8]
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [254 x i8]* %8 to i8*
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 1, i32* %3
br label %69
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 2
br i1 %18, label %25, label %19
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strncmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 2)
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %19, %16
%26 = load i32*, i32** @stdin
store i32* %26, i32** %6
br label %32
27: ; preds = %19
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %31, i32** %6
br label %32
32: ; preds = %27, %25
%33 = load i32*, i32** %6
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %69
37: ; preds = %32
br label %38
38: ; preds = %37, %61
%39 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%40 = load i32*, i32** %6
%41 = call i8* @fgets(i8* %39, i32 257, i32* %40)
store i8* %41, i8** %9
%42 = load i8*, i8** %9
%43 = icmp eq i8* %42, null
br i1 %43, label %52, label %44
44: ; preds = %38
%45 = load i32*, i32** %6
%46 = call i64 @feof(i32* %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %52, label %48
48: ; preds = %44
%49 = load i32*, i32** %6
%50 = call i64 @ferror(i32* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %48, %44, %38
br label %62
53: ; preds = %48
%54 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%55 = getelementptr inbounds [254 x i8], [254 x i8]* %8, i64 0, i64 0
%56 = call i32 @get_domain(i8* %54, i8* %55)
%57 = icmp ne i32 %56, 0
br i1 %57, label %61, label %58
58: ; preds = %53
%59 = getelementptr inbounds [254 x i8], [254 x i8]* %8, i64 0, i64 0
%60 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %59)
br label %61
61: ; preds = %58, %53
br label %38
62: ; preds = %52
%63 = load i32*, i32** %6
%64 = call i64 @ferror(i32* %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %62
%67 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %69
68: ; preds = %62
store i32 0, i32* %3
br label %69
69: ; preds = %68, %66, %35, %13
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@.str = [24 x i8] c"usage: hostsblock file\0A\00"
@stderr = global i32 0
@.str.1 = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [26 x i8] c"error opening filter list\00"
@.str.4 = [6 x i8] c"0\09%s\0A\00"
@.str.5 = [26 x i8] c"error reading filter list\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [257 x i8]
%4 = alloca [254 x i8]
%5 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [254 x i8], [254 x i8]* %4, i64 0, i64 0
%7 = icmp sgt i32 %0, 2
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %50
11: ; preds = %2
%12 = icmp eq i32 %0, 2
br i1 %12, label %13, label %18
13: ; preds = %11
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @strncmp(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 2)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13, %11
%19 = load i32*, i32** @stdin
br label %23
20: ; preds = %13
%21 = load i8*, i8** %14
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %20, %18
%24 = phi i32* [ %19, %18 ], [ %22, %20 ]
%25 = icmp eq i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = call i8* @fgets(i8* %5, i32 257, i32* %24)
%28 = icmp eq i8* %27, null
br i1 %28, label %45, label %31
29: ; preds = %23
%30 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %50
31: ; preds = %26, %42
%32 = call i64 @feof(i32* %24)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %31
%35 = call i64 @ferror(i32* %24)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %34
%38 = call i32 @get_domain(i8* %5, i8* %6)
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br label %42
42: ; preds = %37, %40
%43 = call i8* @fgets(i8* %5, i32 257, i32* %24)
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %31
45: ; preds = %42, %31, %34, %26
%46 = call i64 @ferror(i32* %24)
%47 = icmp eq i64 %46, 0
br i1 %47, label %50, label %48
48: ; preds = %45
%49 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %50
50: ; preds = %45, %48, %29, %8
%51 = phi i32 [ 1, %8 ], [ 1, %29 ], [ 1, %48 ], [ 0, %45 ]
ret i32 %51
}