#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 stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ LOG_NOTICE;
scalar_t__ S_ISLNK(int /*<<< orphan*/);
int /*<<< orphan*/ fix_symlink();
scalar_t__ lstat(char *, struct stat *);
int pia_running();
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
void check_resolv() {
  struct stat r_stat;
  const int pia = pia_running();
  if (lstat("/etc/resolv.conf", &r_stat)) {
    if (!pia) {
      syslog(LOG_INFO, "Failed to stat. Trying to fix because PIA is not "
                       "running right now...");
      fix_symlink();
    } else {
      syslog(LOG_INFO, "Cannot stat, assuming PIA must be writing resolv.conf");
    }
  } else {
    if (S_ISLNK(r_stat.st_mode))
      if (pia)
        syslog(LOG_NOTICE, "Bug? Symlink exists but PIA is running. Weird...");
      else
        syslog(LOG_INFO, "All good, symlink and PIA isn't running");
    else if (pia)
      syslog(LOG_INFO, "All good, not a symlink and PIA is running");
    else
      fix_symlink();
  }
}


x86 assembly (clang, -O0):
<check_resolv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <pia_running@plt>
mov    %eax,-0xc(%rbp)
lea    0xe97(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <lstat@plt>
cmp    $0x0,%rax
je     11c1 <check_resolv+0x71>
cmpl   $0x0,-0xc(%rbp)
jne    11a7 <check_resolv+0x57>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
call   1060 <syslog@plt>
mov    $0x0,%al
call   1070 <fix_symlink@plt>
jmp    11bc <check_resolv+0x6c>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
call   1060 <syslog@plt>
jmp    1246 <check_resolv+0xf6>
mov    -0x8(%rbp),%edi
call   1040 <S_ISLNK@plt>
cmp    $0x0,%rax
je     1211 <check_resolv+0xc1>
cmpl   $0x0,-0xc(%rbp)
je     11f7 <check_resolv+0xa7>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
call   1060 <syslog@plt>
jmp    120c <check_resolv+0xbc>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xeb7(%rip),%rsi
call   1060 <syslog@plt>
jmp    1241 <check_resolv+0xf1>
cmpl   $0x0,-0xc(%rbp)
je     1235 <check_resolv+0xe5>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xebb(%rip),%rsi
call   1060 <syslog@plt>
jmp    123c <check_resolv+0xec>
mov    $0x0,%al
call   1070 <fix_symlink@plt>
jmp    1241 <check_resolv+0xf1>
jmp    1246 <check_resolv+0xf6>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_resolv>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1030 <pia_running@plt>
mov    %eax,%ebx
lea    0xe9b(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <lstat@plt>
test   %rax,%rax
je     118a <check_resolv+0x3a>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
test   %ebx,%ebx
je     11ae <check_resolv+0x5e>
lea    0xecf(%rip),%rsi
jmp    11ec <check_resolv+0x9c>
mov    0x8(%rsp),%edi
call   1040 <S_ISLNK@plt>
test   %rax,%rax
je     11c6 <check_resolv+0x76>
test   %ebx,%ebx
je     11dc <check_resolv+0x8c>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xee1(%rip),%rsi
jmp    11ec <check_resolv+0x9c>
lea    0xe5c(%rip),%rsi
call   1060 <syslog@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
jmp    1070 <fix_symlink@plt>
test   %ebx,%ebx
je     11ba <check_resolv+0x6a>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xf0c(%rip),%rsi
jmp    11ec <check_resolv+0x9c>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xed2(%rip),%rsi
add    $0x10,%rsp
pop    %rbx
jmp    1060 <syslog@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [17 x i8] c"/etc/resolv.conf\00"
@LOG_INFO = global i32 0
@.str.1 = [70 x i8] c"Failed to stat. Trying to fix because PIA is not running right now...\00"
@.str.2 = [54 x i8] c"Cannot stat, assuming PIA must be writing resolv.conf\00"
@LOG_NOTICE = global i32 0
@.str.3 = [49 x i8] c"Bug? Symlink exists but PIA is running. Weird...\00"
@.str.4 = [40 x i8] c"All good, symlink and PIA isn't running\00"
@.str.5 = [43 x i8] c"All good, not a symlink and PIA is running\00"
define void @check_resolv() {
%1 = alloca %struct.stat
%2 = alloca i32
%3 = call i32 (...) @pia_running()
store i32 %3, i32* %2
%4 = call i64 @lstat(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %17
6: ; preds = %0
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %6
%10 = load i32, i32* @LOG_INFO
%11 = call i32 @syslog(i32 %10, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 (...) @fix_symlink()
br label %16
13: ; preds = %6
%14 = load i32, i32* @LOG_INFO
%15 = call i32 @syslog(i32 %14, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %13, %9
br label %42
17: ; preds = %0
%18 = getelementptr inbounds %struct.stat, %struct.stat* %1, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i64 @S_ISLNK(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %17
%23 = load i32, i32* %2
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* @LOG_NOTICE
%27 = call i32 @syslog(i32 %26, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
br label %31
28: ; preds = %22
%29 = load i32, i32* @LOG_INFO
%30 = call i32 @syslog(i32 %29, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %28, %25
br label %41
32: ; preds = %17
%33 = load i32, i32* %2
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* @LOG_INFO
%37 = call i32 @syslog(i32 %36, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
br label %40
38: ; preds = %32
%39 = call i32 (...) @fix_symlink()
br label %40
40: ; preds = %38, %35
br label %41
41: ; preds = %40, %31
br label %42
42: ; preds = %41, %16
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [17 x i8] c"/etc/resolv.conf\00"
@LOG_INFO = global i32 0
@.str.1 = [70 x i8] c"Failed to stat. Trying to fix because PIA is not running right now...\00"
@.str.2 = [54 x i8] c"Cannot stat, assuming PIA must be writing resolv.conf\00"
@LOG_NOTICE = global i32 0
@.str.3 = [49 x i8] c"Bug? Symlink exists but PIA is running. Weird...\00"
@.str.4 = [40 x i8] c"All good, symlink and PIA isn't running\00"
@.str.5 = [43 x i8] c"All good, not a symlink and PIA is running\00"
define void @check_resolv() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = tail call i32 (...) @pia_running()
%4 = call i64 @lstat(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %0
%7 = icmp eq i32 %3, 0
%8 = load i32, i32* @LOG_INFO
br i1 %7, label %9, label %12
9: ; preds = %6
%10 = tail call i32 @syslog(i32 %8, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 (...) @fix_symlink()
br label %33
12: ; preds = %6
%13 = tail call i32 @syslog(i32 %8, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
br label %33
14: ; preds = %0
%15 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%16 = load i32, i32* %15
%17 = tail call i64 @S_ISLNK(i32 %16)
%18 = icmp eq i64 %17, 0
%19 = icmp eq i32 %3, 0
br i1 %18, label %27, label %20
20: ; preds = %14
br i1 %19, label %24, label %21
21: ; preds = %20
%22 = load i32, i32* @LOG_NOTICE
%23 = tail call i32 @syslog(i32 %22, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
br label %33
24: ; preds = %20
%25 = load i32, i32* @LOG_INFO
%26 = tail call i32 @syslog(i32 %25, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %33
27: ; preds = %14
br i1 %19, label %31, label %28
28: ; preds = %27
%29 = load i32, i32* @LOG_INFO
%30 = tail call i32 @syslog(i32 %29, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
br label %33
31: ; preds = %27
%32 = tail call i32 (...) @fix_symlink()
br label %33
33: ; preds = %24, %21, %31, %28, %9, %12
ret void
}