#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 */
int check_for_update();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ free_list();
int getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ read_command();
int /*<<< orphan*/ read_hosts(char *);
char *strchr(char *, char);
char *strdup(char *);
int /*<<< orphan*/ usage(char *);
int /*<<< orphan*/ writeout(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  char *hosts = NULL;
  FILE *fp;
  int c;
  char *me;
  if ((me = strchr(argv[0], '/')))
    me++;
  else
    me = argv[0];
  while ((c = getopt(argc, argv, "f:")) > 0) {
    switch (c) {
    case 'f':
      hosts = strdup(optarg);
      break;
    default:
      usage(me);
      exit(0);
    }
  }
  if (hosts == NULL)
    hosts = strdup("/etc/hosts");
  read_hosts(hosts);
  read_command();
  c = check_for_update();
  if (c && (fp = fopen(hosts, "w"))) {
    writeout(fp);
    fclose(fp);
  }
  free_list();
  if (hosts)
    free(hosts);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2f,%esi
call   1080 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     121e <main+0x4e>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1229 <main+0x59>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    122e <main+0x5e>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdc4(%rip),%rdx
call   10d0 <getopt@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    128b <main+0xbb>
mov    -0x24(%rbp),%eax
sub    $0x66,%eax
jne    1276 <main+0xa6>
jmp    125e <main+0x8e>
mov    0x2d93(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strdup@plt>
mov    %rax,-0x18(%rbp)
jmp    1286 <main+0xb6>
mov    -0x30(%rbp),%rdi
call   10a0 <usage@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
jmp    122e <main+0x5e>
cmpq   $0x0,-0x18(%rbp)
jne    12a6 <main+0xd6>
lea    0xd66(%rip),%rdi
call   10f0 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   10c0 <read_hosts@plt>
mov    $0x0,%al
call   1050 <read_command@plt>
mov    $0x0,%al
call   1070 <check_for_update@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     12fa <main+0x12a>
mov    -0x18(%rbp),%rdi
lea    0xd39(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12fa <main+0x12a>
mov    -0x20(%rbp),%rdi
call   1040 <writeout@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x0,%al
call   1090 <free_list@plt>
cmpq   $0x0,-0x18(%rbp)
je     1315 <main+0x145>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
mov    (%rsi),%r14
mov    %r14,%rdi
mov    $0x2f,%esi
call   1080 <strchr@plt>
mov    %rax,%rbx
lea    0xe06(%rip),%rdx
mov    %ebp,%edi
mov    %r15,%rsi
call   10d0 <getopt@plt>
test   %eax,%eax
jle    124b <main+0x7b>
mov    %rbx,(%rsp)
mov    0x2de5(%rip),%r12
lea    0xde6(%rip),%r13
nopw   0x0(%rax,%rax,1)
cmp    $0x66,%eax
jne    12c0 <main+0xf0>
mov    (%r12),%rdi
call   10f0 <strdup@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r13,%rdx
call   10d0 <getopt@plt>
test   %eax,%eax
jg     1220 <main+0x50>
test   %rbx,%rbx
jne    125a <main+0x8a>
lea    0xdb1(%rip),%rdi
call   10f0 <strdup@plt>
mov    %rax,%rbx
mov    %rbx,%rdi
call   10c0 <read_hosts@plt>
xor    %eax,%eax
call   1050 <read_command@plt>
xor    %eax,%eax
call   1070 <check_for_update@plt>
test   %eax,%eax
je     129b <main+0xcb>
lea    0xd93(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     129b <main+0xcb>
mov    %rax,%rbp
mov    %rax,%rdi
call   1040 <writeout@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
call   1090 <free_list@plt>
test   %rbx,%rbx
je     12af <main+0xdf>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsp),%rax
lea    0x1(%rax),%rdi
test   %rax,%rax
cmove  %r14,%rdi
call   10a0 <usage@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"f:\00"
@optarg = global i8* null
@.str.1 = [11 x i8] c"/etc/hosts\00"
@.str.2 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i8* @strchr(i8* %12, i8 signext 47)
store i8* %13, i8** %9
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i8*, i8** %9
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %9
br label %22
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
store i8* %21, i8** %9
br label %22
22: ; preds = %18, %15
br label %23
23: ; preds = %37, %22
%24 = load i32, i32* %4
%25 = load i8**, i8*** %5
%26 = call i32 @getopt(i32 %24, i8** %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %26, i32* %8
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %38
28: ; preds = %23
%29 = load i32, i32* %8
switch i32 %29, label %33 [
i32 102, label %30
]
30: ; preds = %28
%31 = load i8*, i8** @optarg
%32 = call i8* @strdup(i8* %31)
store i8* %32, i8** %6
br label %37
33: ; preds = %28
%34 = load i8*, i8** %9
%35 = call i32 @usage(i8* %34)
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %30
br label %23
38: ; preds = %23
%39 = load i8*, i8** %6
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i8* @strdup(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i8* %42, i8** %6
br label %43
43: ; preds = %41, %38
%44 = load i8*, i8** %6
%45 = call i32 @read_hosts(i8* %44)
%46 = call i32 (...) @read_command()
%47 = call i32 (...) @check_for_update()
store i32 %47, i32* %8
%48 = load i32, i32* %8
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %59
50: ; preds = %43
%51 = load i8*, i8** %6
%52 = call i32* @fopen(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %52, i32** %7
%53 = icmp ne i32* %52, null
br i1 %53, label %54, label %59
54: ; preds = %50
%55 = load i32*, i32** %7
%56 = call i32 @writeout(i32* %55)
%57 = load i32*, i32** %7
%58 = call i32 @fclose(i32* %57)
br label %59
59: ; preds = %54, %50, %43
%60 = call i32 (...) @free_list()
%61 = load i8*, i8** %6
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = load i8*, i8** %6
%65 = call i32 @free(i8* %64)
br label %66
66: ; preds = %63, %59
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"f:\00"
@optarg = global i8* null
@.str.1 = [11 x i8] c"/etc/hosts\00"
@.str.2 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i8*, i8** %1
%4 = tail call i8* @strchr(i8* dereferenceable(1) %3, i8 signext 47)
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %23
7: ; preds = %2, %10
%8 = phi i32 [ %13, %10 ], [ %5, %2 ]
%9 = icmp eq i32 %8, 102
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = load i8*, i8** @optarg
%12 = tail call i8* @strdup(i8* %11)
%13 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp sgt i32 %13, 0
br i1 %14, label %7, label %21
15: ; preds = %7
%16 = icmp eq i8* %4, null
%17 = getelementptr inbounds i8, i8* %4, i64 1
%18 = select i1 %16, i8* %3, i8* %17
%19 = tail call i32 @usage(i8* %18)
%20 = tail call i32 @exit(i32 0)
unreachable
21: ; preds = %10
%22 = icmp eq i8* %12, null
br i1 %22, label %23, label %25
23: ; preds = %2, %21
%24 = tail call dereferenceable_or_null(11) i8* @strdup(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %21
%26 = phi i8* [ %24, %23 ], [ %12, %21 ]
%27 = tail call i32 @read_hosts(i8* %26)
%28 = tail call i32 (...) @read_command()
%29 = tail call i32 (...) @check_for_update()
%30 = icmp eq i32 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %25
%32 = tail call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp eq i32* %32, null
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = tail call i32 @writeout(i32* %32)
%36 = tail call i32 @fclose(i32* %32)
br label %37
37: ; preds = %34, %31, %25
%38 = tail call i32 (...) @free_list()
%39 = icmp eq i8* %26, null
br i1 %39, label %42, label %40
40: ; preds = %37
%41 = tail call i32 @free(i8* %26)
br label %42
42: ; preds = %40, %37
ret i32 0
}