#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ uid_t;
struct TYPE_4__ {
  unsigned int gl_pathc;
  char **gl_pathv;
};
typedef TYPE_1__ glob_t;
typedef int /*<<< orphan*/ gid_t;

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ EOPNOTSUPP;
int /*<<< orphan*/ GLOB_NOSORT;
int /*<<< orphan*/ LOG_ERR;
scalar_t__ chflags(char *, int /*<<< orphan*/);
scalar_t__ chmod(char *, int);
scalar_t__ chown(char *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ errno;
scalar_t__ glob(char *, int /*<<< orphan*/, int /*<<< orphan*/ *, TYPE_1__ *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char const *, char *);
void login_protect(const char *table, char *pattern, int mask, uid_t uid,
                   gid_t gid) {
  glob_t gl;
  char *path;
  unsigned int i;
  if (glob(pattern, GLOB_NOSORT, NULL, &gl) != 0)
    return;
  for (i = 0; i < gl.gl_pathc; i++) {
    path = gl.gl_pathv[i];
    if (chflags(path, 0) && errno != ENOENT && errno != EOPNOTSUPP)
      syslog(LOG_ERR, "%s: chflags(%s): %m", table, path);
    if (chmod(path, mask) && errno != ENOENT)
      syslog(LOG_ERR, "%s: chmod(%s): %m", table, path);
    if (chown(path, uid, gid) && errno != ENOENT)
      syslog(LOG_ERR, "%s: chown(%s): %m", table, path);
  }
  globfree(&gl);
}


x86 assembly (clang, -O0):
<login_protect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x30(%rbp),%rcx
call   1080 <glob@plt>
cmp    $0x0,%rax
je     11a3 <login_protect+0x43>
jmp    12e4 <login_protect+0x184>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jae    12db <login_protect+0x17b>
mov    -0x28(%rbp),%rax
mov    -0x3c(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
call   1040 <chflags@plt>
cmp    $0x0,%rax
je     122b <login_protect+0xcb>
mov    0x2df7(%rip),%rax
mov    (%rax),%rax
mov    0x2dd5(%rip),%rcx
cmp    (%rcx),%rax
je     122b <login_protect+0xcb>
mov    0x2ddd(%rip),%rax
mov    (%rax),%rax
mov    0x2ddb(%rip),%rcx
cmp    (%rcx),%rax
je     122b <login_protect+0xcb>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    0xdda(%rip),%rsi
call   1050 <syslog@plt>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <chmod@plt>
cmp    $0x0,%rax
je     1278 <login_protect+0x118>
mov    0x2d90(%rip),%rax
mov    (%rax),%rax
mov    0x2d6e(%rip),%rcx
cmp    (%rcx),%rax
je     1278 <login_protect+0x118>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    0xda1(%rip),%rsi
call   1050 <syslog@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1060 <chown@plt>
cmp    $0x0,%rax
je     12c8 <login_protect+0x168>
mov    0x2d40(%rip),%rax
mov    (%rax),%rax
mov    0x2d1e(%rip),%rcx
cmp    (%rcx),%rax
je     12c8 <login_protect+0x168>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    0xd63(%rip),%rsi
call   1050 <syslog@plt>
jmp    12cd <login_protect+0x16d>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11aa <login_protect+0x4a>
lea    -0x30(%rbp),%rdi
call   1030 <globfree@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<login_protect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r14d
mov    %ecx,%ebx
mov    %edx,%r15d
mov    %rsi,%rax
mov    %rdi,%rbp
mov    0x2e4d(%rip),%rcx
mov    (%rcx),%esi
lea    0x8(%rsp),%rcx
mov    %rax,%rdi
xor    %edx,%edx
call   1080 <glob@plt>
test   %rax,%rax
jne    12ae <login_protect+0x14e>
mov    %rbp,(%rsp)
cmpl   $0x0,0x8(%rsp)
je     12a4 <login_protect+0x144>
mov    %r14d,%ebp
xor    %r12d,%r12d
mov    0x2e07(%rip),%r14
jmp    11d1 <login_protect+0x71>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
mov    0x8(%rsp),%eax
cmp    %rax,%r12
jae    12a4 <login_protect+0x144>
mov    0x10(%rsp),%rax
mov    (%rax,%r12,8),%r13
mov    %r13,%rdi
xor    %esi,%esi
call   1040 <chflags@plt>
test   %rax,%rax
je     1220 <login_protect+0xc0>
mov    0x2de8(%rip),%rax
mov    (%rax),%rax
cmp    (%r14),%rax
je     1220 <login_protect+0xc0>
mov    0x2de1(%rip),%rcx
cmp    (%rcx),%rax
je     1220 <login_protect+0xc0>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
mov    (%rsp),%rdx
mov    %r13,%rcx
call   1050 <syslog@plt>
mov    %r13,%rdi
mov    %r15d,%esi
call   1070 <chmod@plt>
test   %rax,%rax
je     125b <login_protect+0xfb>
mov    0x2da1(%rip),%rax
mov    (%rax),%rax
cmp    (%r14),%rax
je     125b <login_protect+0xfb>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
lea    0xdc5(%rip),%rsi
mov    (%rsp),%rdx
mov    %r13,%rcx
call   1050 <syslog@plt>
mov    %r13,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1060 <chown@plt>
test   %rax,%rax
je     11c0 <login_protect+0x60>
mov    0x2d61(%rip),%rax
mov    (%rax),%rax
cmp    (%r14),%rax
je     11c0 <login_protect+0x60>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
lea    0xd93(%rip),%rsi
mov    (%rsp),%rdx
mov    %r13,%rcx
call   1050 <syslog@plt>
jmp    11c0 <login_protect+0x60>
lea    0x8(%rsp),%rdi
call   1030 <globfree@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i8** }
@GLOB_NOSORT = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@EOPNOTSUPP = global i64 0
@LOG_ERR = global i32 0
@.str = [20 x i8] c"%s: chflags(%s): %m\00"
@.str.1 = [18 x i8] c"%s: chmod(%s): %m\00"
@.str.2 = [18 x i8] c"%s: chown(%s): %m\00"
define void @login_protect(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.TYPE_4__
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%14 = load i8*, i8** %7
%15 = load i32, i32* @GLOB_NOSORT
%16 = call i64 @glob(i8* %14, i32 %15, i32* null, %struct.TYPE_4__* %11)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %5
br label %83
19: ; preds = %5
store i32 0, i32* %13
br label %20
20: ; preds = %78, %19
%21 = load i32, i32* %13
%22 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %11, i32 0, i32 0
%23 = load i32, i32* %22
%24 = icmp ult i32 %21, %23
br i1 %24, label %25, label %81
25: ; preds = %20
%26 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %11, i32 0, i32 1
%27 = load i8**, i8*** %26
%28 = load i32, i32* %13
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
store i8* %31, i8** %12
%32 = load i8*, i8** %12
%33 = call i64 @chflags(i8* %32, i32 0)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %48
35: ; preds = %25
%36 = load i64, i64* @errno
%37 = load i64, i64* @ENOENT
%38 = icmp ne i64 %36, %37
br i1 %38, label %39, label %48
39: ; preds = %35
%40 = load i64, i64* @errno
%41 = load i64, i64* @EOPNOTSUPP
%42 = icmp ne i64 %40, %41
br i1 %42, label %43, label %48
43: ; preds = %39
%44 = load i32, i32* @LOG_ERR
%45 = load i8*, i8** %6
%46 = load i8*, i8** %12
%47 = call i32 @syslog(i32 %44, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %45, i8* %46)
br label %48
48: ; preds = %43, %39, %35, %25
%49 = load i8*, i8** %12
%50 = load i32, i32* %8
%51 = call i64 @chmod(i8* %49, i32 %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %62
53: ; preds = %48
%54 = load i64, i64* @errno
%55 = load i64, i64* @ENOENT
%56 = icmp ne i64 %54, %55
br i1 %56, label %57, label %62
57: ; preds = %53
%58 = load i32, i32* @LOG_ERR
%59 = load i8*, i8** %6
%60 = load i8*, i8** %12
%61 = call i32 @syslog(i32 %58, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %59, i8* %60)
br label %62
62: ; preds = %57, %53, %48
%63 = load i8*, i8** %12
%64 = load i32, i32* %9
%65 = load i32, i32* %10
%66 = call i64 @chown(i8* %63, i32 %64, i32 %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %77
68: ; preds = %62
%69 = load i64, i64* @errno
%70 = load i64, i64* @ENOENT
%71 = icmp ne i64 %69, %70
br i1 %71, label %72, label %77
72: ; preds = %68
%73 = load i32, i32* @LOG_ERR
%74 = load i8*, i8** %6
%75 = load i8*, i8** %12
%76 = call i32 @syslog(i32 %73, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %74, i8* %75)
br label %77
77: ; preds = %72, %68, %62
br label %78
78: ; preds = %77
%79 = load i32, i32* %13
%80 = add i32 %79, 1
store i32 %80, i32* %13
br label %20
81: ; preds = %20
%82 = call i32 @globfree(%struct.TYPE_4__* %11)
br label %83
83: ; preds = %81, %18
ret void
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i8** }
@GLOB_NOSORT = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@EOPNOTSUPP = global i64 0
@LOG_ERR = global i32 0
@.str = [20 x i8] c"%s: chflags(%s): %m\00"
@.str.1 = [18 x i8] c"%s: chmod(%s): %m\00"
@.str.2 = [18 x i8] c"%s: chown(%s): %m\00"
define void @login_protect(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca %struct.TYPE_4__
%7 = bitcast %struct.TYPE_4__* %6 to i8*
%8 = load i32, i32* @GLOB_NOSORT
%9 = call i64 @glob(i8* %1, i32 %8, i32* null, %struct.TYPE_4__* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %61
11: ; preds = %5
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 0
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, 0
br i1 %14, label %59, label %15
15: ; preds = %11
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i64 0, i32 1
br label %17
17: ; preds = %15, %54
%18 = phi i64 [ 0, %15 ], [ %55, %54 ]
%19 = load i8**, i8*** %16
%20 = getelementptr inbounds i8*, i8** %19, i64 %18
%21 = load i8*, i8** %20
%22 = call i64 @chflags(i8* %21, i32 0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %34, label %24
24: ; preds = %17
%25 = load i64, i64* @errno
%26 = load i64, i64* @ENOENT
%27 = icmp eq i64 %25, %26
%28 = load i64, i64* @EOPNOTSUPP
%29 = icmp eq i64 %25, %28
%30 = select i1 %27, i1 true, i1 %29
br i1 %30, label %34, label %31
31: ; preds = %24
%32 = load i32, i32* @LOG_ERR
%33 = call i32 @syslog(i32 %32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %21)
br label %34
34: ; preds = %31, %24, %17
%35 = call i64 @chmod(i8* %21, i32 %2)
%36 = icmp eq i64 %35, 0
br i1 %36, label %44, label %37
37: ; preds = %34
%38 = load i64, i64* @errno
%39 = load i64, i64* @ENOENT
%40 = icmp eq i64 %38, %39
br i1 %40, label %44, label %41
41: ; preds = %37
%42 = load i32, i32* @LOG_ERR
%43 = call i32 @syslog(i32 %42, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %21)
br label %44
44: ; preds = %41, %37, %34
%45 = call i64 @chown(i8* %21, i32 %3, i32 %4)
%46 = icmp eq i64 %45, 0
br i1 %46, label %54, label %47
47: ; preds = %44
%48 = load i64, i64* @errno
%49 = load i64, i64* @ENOENT
%50 = icmp eq i64 %48, %49
br i1 %50, label %54, label %51
51: ; preds = %47
%52 = load i32, i32* @LOG_ERR
%53 = call i32 @syslog(i32 %52, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %21)
br label %54
54: ; preds = %44, %47, %51
%55 = add nuw nsw i64 %18, 1
%56 = load i32, i32* %12
%57 = zext i32 %56 to i64
%58 = icmp ult i64 %55, %57
br i1 %58, label %17, label %59
59: ; preds = %54, %11
%60 = call i32 @globfree(%struct.TYPE_4__* %6)
br label %61
61: ; preds = %5, %59
ret void
}