#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 /*<<< orphan*/ FD_CLOEXEC;
int /*<<< orphan*/ F_SETFD;
int O_NONBLOCK;
int O_RDONLY;
int /*<<< orphan*/ close(int);
int f_webuserok(char const *, int /*<<< orphan*/ *, char *, int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ log_d(char *, ...);
int open(char const *, int);
int webuserok(const char *authorization, const char *userfilename,
              char *username, int len, int do_crypt) {
  FILE *f;
  int fd;
  int retval;
  fd = open(userfilename, O_RDONLY | O_NONBLOCK);
  if (fd == -1) {
    log_d("cannot open userfile %s", userfilename);
    return 0;
  }
  fcntl(fd, F_SETFD, FD_CLOEXEC);
  f = fdopen(fd, "r");
  if (f == 0) {
    log_d("webuserok: fdopen failed");
    close(fd);
    return 0;
  }
  retval = f_webuserok(authorization, f, username, len, do_crypt);
  fclose(f);
  return retval;
}


x86 assembly (clang, -O0):
<webuserok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
mov    0x2e49(%rip),%rax
or     (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    11d1 <webuserok+0x61>
mov    -0x18(%rbp),%rsi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <log_d@plt>
movl   $0x0,-0x4(%rbp)
jmp    1255 <webuserok+0xe5>
mov    -0x34(%rbp),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
call   1040 <fcntl@plt>
mov    -0x34(%rbp),%edi
lea    0xe23(%rip),%rsi
call   1080 <fdopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    122b <webuserok+0xbb>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <log_d@plt>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1255 <webuserok+0xe5>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
call   1070 <f_webuserok@plt>
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<webuserok>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rsi,%rbp
mov    %rdi,%r13
mov    0x2e4f(%rip),%rax
mov    0x2e50(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbp,%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     11fc <webuserok+0x8c>
mov    %eax,%ebx
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
call   1040 <fcntl@plt>
lea    0xe4d(%rip),%rsi
mov    %ebx,%edi
call   1080 <fdopen@plt>
test   %rax,%rax
je     120f <webuserok+0x9f>
mov    %rax,%rbp
mov    %r13,%rdi
mov    %rax,%rsi
mov    %r12,%rdx
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1070 <f_webuserok@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %ebx,%eax
jmp    1226 <webuserok+0xb6>
lea    0xdfd(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1030 <log_d@plt>
jmp    1224 <webuserok+0xb4>
lea    0xe04(%rip),%rdi
xor    %eax,%eax
call   1030 <log_d@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str = [24 x i8] c"cannot open userfile %s\00"
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"webuserok: fdopen failed\00"
define i32 @webuserok(i8* %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%15 = load i8*, i8** %8
%16 = load i32, i32* @O_RDONLY
%17 = load i32, i32* @O_NONBLOCK
%18 = or i32 %16, %17
%19 = call i32 @open(i8* %15, i32 %18)
store i32 %19, i32* %13
%20 = load i32, i32* %13
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %5
%23 = load i8*, i8** %8
%24 = call i32 (i8*, ...) @log_d(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %23)
store i32 0, i32* %6
br label %48
25: ; preds = %5
%26 = load i32, i32* %13
%27 = load i32, i32* @F_SETFD
%28 = load i32, i32* @FD_CLOEXEC
%29 = call i32 @fcntl(i32 %26, i32 %27, i32 %28)
%30 = load i32, i32* %13
%31 = call i32* @fdopen(i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %12
%32 = load i32*, i32** %12
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %38
34: ; preds = %25
%35 = call i32 (i8*, ...) @log_d(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* %13
%37 = call i32 @close(i32 %36)
store i32 0, i32* %6
br label %48
38: ; preds = %25
%39 = load i8*, i8** %7
%40 = load i32*, i32** %12
%41 = load i8*, i8** %9
%42 = load i32, i32* %10
%43 = load i32, i32* %11
%44 = call i32 @f_webuserok(i8* %39, i32* %40, i8* %41, i32 %42, i32 %43)
store i32 %44, i32* %14
%45 = load i32*, i32** %12
%46 = call i32 @fclose(i32* %45)
%47 = load i32, i32* %14
store i32 %47, i32* %6
br label %48
48: ; preds = %38, %34, %22
%49 = load i32, i32* %6
ret i32 %49
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str = [24 x i8] c"cannot open userfile %s\00"
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"webuserok: fdopen failed\00"
define i32 @webuserok(i8* %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = load i32, i32* @O_RDONLY
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %7, %6
%9 = tail call i32 @open(i8* %1, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = tail call i32 (i8*, ...) @log_d(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %25
13: ; preds = %5
%14 = load i32, i32* @F_SETFD
%15 = load i32, i32* @FD_CLOEXEC
%16 = tail call i32 @fcntl(i32 %9, i32 %14, i32 %15)
%17 = tail call i32* @fdopen(i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = tail call i32 (i8*, ...) @log_d(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%21 = tail call i32 @close(i32 %9)
br label %25
22: ; preds = %13
%23 = tail call i32 @f_webuserok(i8* %0, i32* %17, i8* %2, i32 %3, i32 %4)
%24 = tail call i32 @fclose(i32* %17)
br label %25
25: ; preds = %22, %19, %11
%26 = phi i32 [ 0, %11 ], [ 0, %19 ], [ %23, %22 ]
ret i32 %26
}