#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 _POSIX2_LINE_MAX;
char *getenv(char *);
int readlink(char *, char *, int);
scalar_t__ strcmp(char *, char const *);
int /*<<< orphan*/ strlcpy(char *, char *, int);
char *strsep(char **, char *);
int check_utility_compat(const char *utility) {
  char buf[_POSIX2_LINE_MAX];
  char *p, *bp;
  int len;
  if ((p = getenv("_COMPAT_FreeBSD_4")) != NULL) {
    strlcpy(buf, p, sizeof buf);
  } else {
    if ((len = readlink("/etc/compat-FreeBSD-4-util", buf, sizeof buf)) < 0)
      return 0;
    if (len > sizeof buf)
      len = sizeof buf;
    buf[len] = '\0';
  }
  if (buf[0] == '\0')
    return 1;
  bp = buf;
  while ((p = strsep(&bp, ",")) != NULL) {
    if (strcmp(p, utility) == 0)
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_utility_compat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    0xe6d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11be <check_utility_compat+0x6e>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1070 <strlcpy@plt>
jmp    1217 <check_utility_compat+0xc7>
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rax
mov    %eax,%edx
lea    0xe43(%rip),%rdi
call   1040 <readlink@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    11f3 <check_utility_compat+0xa3>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    129d <check_utility_compat+0x14d>
mov    -0x48(%rbp),%rcx
movslq -0x34(%rbp),%rax
cmp    %rcx,%rax
jbe    120b <check_utility_compat+0xbb>
mov    -0x48(%rbp),%rax
mov    %eax,-0x34(%rbp)
mov    -0x40(%rbp),%rax
movslq -0x34(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    123a <check_utility_compat+0xea>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    129d <check_utility_compat+0x14d>
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xde0(%rip),%rsi
call   1060 <strsep@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     128f <check_utility_compat+0x13f>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    128a <check_utility_compat+0x13a>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    129d <check_utility_compat+0x14d>
jmp    1242 <check_utility_compat+0xf2>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_utility_compat>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2e7f(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%rbx
mov    %r15,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe79(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11a1 <check_utility_compat+0x51>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r15d,%edx
call   1070 <strlcpy@plt>
jmp    11c2 <check_utility_compat+0x72>
lea    0xe6a(%rip),%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1040 <readlink@plt>
test   %eax,%eax
js     1202 <check_utility_compat+0xb2>
cmp    %r15d,%eax
cmova  %r15d,%eax
movb   $0x0,(%rbx,%rax,1)
mov    $0x1,%r15d
cmpb   $0x0,(%rbx)
je     1205 <check_utility_compat+0xb5>
mov    %rbx,-0x28(%rbp)
lea    0xe55(%rip),%r12
lea    -0x28(%rbp),%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strsep@plt>
test   %rax,%rax
je     1202 <check_utility_compat+0xb2>
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11e0 <check_utility_compat+0x90>
jmp    1205 <check_utility_compat+0xb5>
xor    %r15d,%r15d
mov    %r15d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@_POSIX2_LINE_MAX = global i32 0
@.str = [18 x i8] c"_COMPAT_FreeBSD_4\00"
@.str.1 = [27 x i8] c"/etc/compat-FreeBSD-4-util\00"
@.str.2 = [2 x i8] c",\00"
define i32 @check_utility_compat(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
%10 = load i32, i32* @_POSIX2_LINE_MAX
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %4
%13 = alloca i8, i64 %11
store i64 %11, i64* %5
%14 = call i8* @getenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %1
%17 = load i8*, i8** %6
%18 = trunc i64 %11 to i32
%19 = call i32 @strlcpy(i8* %13, i8* %17, i32 %18)
br label %35
20: ; preds = %1
%21 = trunc i64 %11 to i32
%22 = call i32 @readlink(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32 %21)
store i32 %22, i32* %8
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 0, i32* %2
store i32 1, i32* %9
br label %53
25: ; preds = %20
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = icmp ugt i64 %27, %11
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = trunc i64 %11 to i32
store i32 %30, i32* %8
br label %31
31: ; preds = %29, %25
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %13, i64 %33
store i8 0, i8* %34
br label %35
35: ; preds = %31, %16
%36 = getelementptr inbounds i8, i8* %13, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
store i32 1, i32* %2
store i32 1, i32* %9
br label %53
41: ; preds = %35
store i8* %13, i8** %7
br label %42
42: ; preds = %51, %41
%43 = call i8* @strsep(i8** %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %43, i8** %6
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %52
45: ; preds = %42
%46 = load i8*, i8** %6
%47 = load i8*, i8** %3
%48 = call i64 @strcmp(i8* %46, i8* %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %45
store i32 1, i32* %2
store i32 1, i32* %9
br label %53
51: ; preds = %45
br label %42
52: ; preds = %42
store i32 0, i32* %2
store i32 1, i32* %9
br label %53
53: ; preds = %52, %50, %40, %24
%54 = load i8*, i8** %4
%55 = load i32, i32* %2
ret i32 %55
}

LLVM IR (-O2):
@_POSIX2_LINE_MAX = global i32 0
@.str = [18 x i8] c"_COMPAT_FreeBSD_4\00"
@.str.1 = [27 x i8] c"/etc/compat-FreeBSD-4-util\00"
@.str.2 = [2 x i8] c",\00"
define i32 @check_utility_compat(i8* %0) {
%2 = alloca i8*
%3 = load i32, i32* @_POSIX2_LINE_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = bitcast i8** %2 to i8*
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = call i32 @strlcpy(i8* %5, i8* %7, i32 %3)
br label %19
11: ; preds = %1
%12 = call i32 @readlink(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %5, i32 %3)
%13 = icmp slt i32 %12, 0
br i1 %13, label %29, label %14
14: ; preds = %11
%15 = icmp ugt i32 %12, %3
%16 = select i1 %15, i32 %3, i32 %12
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %5, i64 %17
store i8 0, i8* %18
br label %19
19: ; preds = %14, %9
%20 = load i8, i8* %5
%21 = icmp eq i8 %20, 0
br i1 %21, label %29, label %22
22: ; preds = %19
store i8* %5, i8** %2
br label %23
23: ; preds = %26, %22
%24 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i8* %24, null
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = call i64 @strcmp(i8* %24, i8* %0)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %23
29: ; preds = %23, %26, %19, %11
%30 = phi i32 [ 0, %11 ], [ 1, %19 ], [ 0, %23 ], [ 1, %26 ]
ret i32 %30
}