#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*/ X509_LOOKUP;

/* Variables and functions */
long X509_FILETYPE_DEFAULT;
long X509_FILETYPE_PEM;
int /*<<< orphan*/ X509_F_BY_FILE_CTRL;
#define X509_L_FILE_LOAD 128
int /*<<< orphan*/ X509_R_LOADING_DEFAULTS;
char const *X509_get_default_cert_file();
int /*<<< orphan*/ X509_get_default_cert_file_env();
int /*<<< orphan*/ X509_load_cert_crl_file(int /*<<< orphan*/ *, char const *,
                                           long);
int /*<<< orphan*/ X509_load_cert_file(int /*<<< orphan*/ *, char const *, int);
int /*<<< orphan*/ X509err(int /*<<< orphan*/, int /*<<< orphan*/);
char *getenv(int /*<<< orphan*/);
int /*<<< orphan*/ issetugid();
int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
                 char **ret) {
  int ok = 0;
  char *file = NULL;
  switch (cmd) {
  case X509_L_FILE_LOAD:
    if (argl == X509_FILETYPE_DEFAULT) {
      if (issetugid() == 0)
        file = getenv(X509_get_default_cert_file_env());
      if (file)
        ok = (X509_load_cert_crl_file(ctx, file, X509_FILETYPE_PEM) != 0);
      else
        ok = (X509_load_cert_crl_file(ctx, X509_get_default_cert_file(),
                                      X509_FILETYPE_PEM) != 0);
      if (!ok) {
        X509err(X509_F_BY_FILE_CTRL, X509_R_LOADING_DEFAULTS);
      }
    } else {
      if (argl == X509_FILETYPE_PEM)
        ok = (X509_load_cert_crl_file(ctx, argp, X509_FILETYPE_PEM) != 0);
      else
        ok = (X509_load_cert_file(ctx, argp, (int)argl) != 0);
    }
    break;
  }
  return (ok);
}


x86 assembly (clang, -O0):
<by_file_ctrl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x80,%eax
jne    12da <by_file_ctrl+0x16a>
jmp    11ad <by_file_ctrl+0x3d>
mov    -0x20(%rbp),%rax
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%rax
jne    1271 <by_file_ctrl+0x101>
mov    $0x0,%al
call   1050 <issetugid@plt>
cmp    $0x0,%eax
jne    11e3 <by_file_ctrl+0x73>
mov    $0x0,%al
call   1090 <X509_get_default_cert_file_env@plt>
mov    %eax,%edi
call   1030 <getenv@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1218 <by_file_ctrl+0xa8>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    0x2deb(%rip),%rax
mov    (%rax),%rdx
call   1080 <X509_load_cert_crl_file@plt>
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
jmp    124b <by_file_ctrl+0xdb>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1060 <X509_get_default_cert_file@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rsi
mov    0x2db3(%rip),%rax
mov    (%rax),%rdx
call   1080 <X509_load_cert_crl_file@plt>
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    126c <by_file_ctrl+0xfc>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
mov    0x2d63(%rip),%rax
mov    (%rax),%esi
call   1070 <X509err@plt>
jmp    12d5 <by_file_ctrl+0x165>
mov    -0x20(%rbp),%rax
mov    0x2d6c(%rip),%rcx
cmp    (%rcx),%rax
jne    12af <by_file_ctrl+0x13f>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2d54(%rip),%rax
mov    (%rax),%rdx
call   1080 <X509_load_cert_crl_file@plt>
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
jmp    12d0 <by_file_ctrl+0x160>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    %eax,%edx
call   1040 <X509_load_cert_file@plt>
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
jmp    12d5 <by_file_ctrl+0x165>
jmp    12da <by_file_ctrl+0x16a>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<by_file_ctrl>:
push   %rbx
cmp    $0x80,%esi
jne    11df <by_file_ctrl+0x6f>
mov    %rdi,%rbx
mov    0x2e6d(%rip),%rax
cmp    %rcx,(%rax)
jne    11e3 <by_file_ctrl+0x73>
xor    %eax,%eax
call   1050 <issetugid@plt>
test   %eax,%eax
jne    11a6 <by_file_ctrl+0x36>
xor    %eax,%eax
call   1090 <X509_get_default_cert_file_env@plt>
mov    %eax,%edi
call   1030 <getenv@plt>
test   %rax,%rax
jne    11ad <by_file_ctrl+0x3d>
xor    %eax,%eax
call   1060 <X509_get_default_cert_file@plt>
mov    0x2e34(%rip),%rcx
mov    (%rcx),%rdx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1080 <X509_load_cert_crl_file@plt>
mov    $0x1,%cl
test   %eax,%eax
jne    1211 <by_file_ctrl+0xa1>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
call   1070 <X509err@plt>
xor    %ecx,%ecx
jmp    1211 <by_file_ctrl+0xa1>
mov    0x2dfe(%rip),%rax
cmp    %rcx,(%rax)
jne    11ff <by_file_ctrl+0x8f>
mov    %rbx,%rdi
mov    %rdx,%rsi
mov    %rcx,%rdx
call   1080 <X509_load_cert_crl_file@plt>
jmp    120c <by_file_ctrl+0x9c>
mov    %rbx,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
call   1040 <X509_load_cert_file@plt>
test   %eax,%eax
setne  %cl
movzbl %cl,%eax
pop    %rbx
ret

LLVM IR (-O0):
@X509_FILETYPE_DEFAULT = global i64 0
@X509_FILETYPE_PEM = global i64 0
@X509_F_BY_FILE_CTRL = global i32 0
@X509_R_LOADING_DEFAULTS = global i32 0
define i32 @by_file_ctrl(i32* %0, i32 %1, i8* %2, i64 %3, i8** %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8**
%11 = alloca i32
%12 = alloca i8*
store i32* %0, i32** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i8** %4, i8*** %10
store i32 0, i32* %11
store i8* null, i8** %12
%13 = load i32, i32* %7
switch i32 %13, label %70 [
i32 128, label %14
]
14: ; preds = %5
%15 = load i64, i64* %9
%16 = load i64, i64* @X509_FILETYPE_DEFAULT
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %49
18: ; preds = %14
%19 = call i32 (...) @issetugid()
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = call i32 (...) @X509_get_default_cert_file_env()
%23 = call i8* @getenv(i32 %22)
store i8* %23, i8** %12
br label %24
24: ; preds = %21, %18
%25 = load i8*, i8** %12
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = load i32*, i32** %6
%29 = load i8*, i8** %12
%30 = load i64, i64* @X509_FILETYPE_PEM
%31 = call i32 @X509_load_cert_crl_file(i32* %28, i8* %29, i64 %30)
%32 = icmp ne i32 %31, 0
%33 = zext i1 %32 to i32
store i32 %33, i32* %11
br label %41
34: ; preds = %24
%35 = load i32*, i32** %6
%36 = call i8* (...) @X509_get_default_cert_file()
%37 = load i64, i64* @X509_FILETYPE_PEM
%38 = call i32 @X509_load_cert_crl_file(i32* %35, i8* %36, i64 %37)
%39 = icmp ne i32 %38, 0
%40 = zext i1 %39 to i32
store i32 %40, i32* %11
br label %41
41: ; preds = %34, %27
%42 = load i32, i32* %11
%43 = icmp ne i32 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %41
%45 = load i32, i32* @X509_F_BY_FILE_CTRL
%46 = load i32, i32* @X509_R_LOADING_DEFAULTS
%47 = call i32 @X509err(i32 %45, i32 %46)
br label %48
48: ; preds = %44, %41
br label %69
49: ; preds = %14
%50 = load i64, i64* %9
%51 = load i64, i64* @X509_FILETYPE_PEM
%52 = icmp eq i64 %50, %51
br i1 %52, label %53, label %60
53: ; preds = %49
%54 = load i32*, i32** %6
%55 = load i8*, i8** %8
%56 = load i64, i64* @X509_FILETYPE_PEM
%57 = call i32 @X509_load_cert_crl_file(i32* %54, i8* %55, i64 %56)
%58 = icmp ne i32 %57, 0
%59 = zext i1 %58 to i32
store i32 %59, i32* %11
br label %68
60: ; preds = %49
%61 = load i32*, i32** %6
%62 = load i8*, i8** %8
%63 = load i64, i64* %9
%64 = trunc i64 %63 to i32
%65 = call i32 @X509_load_cert_file(i32* %61, i8* %62, i32 %64)
%66 = icmp ne i32 %65, 0
%67 = zext i1 %66 to i32
store i32 %67, i32* %11
br label %68
68: ; preds = %60, %53
br label %69
69: ; preds = %68, %48
br label %70
70: ; preds = %5, %69
%71 = load i32, i32* %11
ret i32 %71
}

LLVM IR (-O2):
@X509_FILETYPE_DEFAULT = global i64 0
@X509_FILETYPE_PEM = global i64 0
@X509_F_BY_FILE_CTRL = global i32 0
@X509_R_LOADING_DEFAULTS = global i32 0
define i32 @by_file_ctrl(i32* %0, i32 %1, i8* %2, i64 %3, i8** nocapture readnone %4) {
%6 = icmp eq i32 %1, 128
br i1 %6, label %7, label %41
7: ; preds = %5
%8 = load i64, i64* @X509_FILETYPE_DEFAULT
%9 = icmp eq i64 %8, %3
br i1 %9, label %10, label %31
10: ; preds = %7
%11 = tail call i32 (...) @issetugid()
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = tail call i32 (...) @X509_get_default_cert_file_env()
%15 = tail call i8* @getenv(i32 %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = load i64, i64* @X509_FILETYPE_PEM
%19 = tail call i32 @X509_load_cert_crl_file(i32* %0, i8* %15, i64 %18)
br label %24
20: ; preds = %10, %13
%21 = tail call i8* (...) @X509_get_default_cert_file()
%22 = load i64, i64* @X509_FILETYPE_PEM
%23 = tail call i32 @X509_load_cert_crl_file(i32* %0, i8* %21, i64 %22)
br label %24
24: ; preds = %20, %17
%25 = phi i32 [ %19, %17 ], [ %23, %20 ]
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %41
27: ; preds = %24
%28 = load i32, i32* @X509_F_BY_FILE_CTRL
%29 = load i32, i32* @X509_R_LOADING_DEFAULTS
%30 = tail call i32 @X509err(i32 %28, i32 %29)
br label %41
31: ; preds = %7
%32 = load i64, i64* @X509_FILETYPE_PEM
%33 = icmp eq i64 %32, %3
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = tail call i32 @X509_load_cert_crl_file(i32* %0, i8* %2, i64 %3)
%36 = icmp ne i32 %35, 0
br label %41
37: ; preds = %31
%38 = trunc i64 %3 to i32
%39 = tail call i32 @X509_load_cert_file(i32* %0, i8* %2, i32 %38)
%40 = icmp ne i32 %39, 0
br label %41
41: ; preds = %27, %24, %37, %34, %5
%42 = phi i1 [ true, %24 ], [ false, %27 ], [ %36, %34 ], [ %40, %37 ], [ false, %5 ]
%43 = zext i1 %42 to i32
ret i32 %43
}