#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 */
char *_PATH_BSHELL;
int /*<<< orphan*/ endusershell();
char *getusershell();
int /*<<< orphan*/ setusershell();
scalar_t__ strcmp(char *, char const *);
int smbftpd_valid_shell(const char *shell) {
  char *ptr;
  if (shell == NULL || *shell == 0) {
    shell = _PATH_BSHELL;
  }
  setusershell();
  while ((ptr = getusershell()) != NULL) {
    if (strcmp(ptr, shell) == 0) {
      break;
    }
  }
  endusershell();
  if (ptr == NULL) {
    return -1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<smbftpd_valid_shell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1167 <smbftpd_valid_shell+0x27>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1175 <smbftpd_valid_shell+0x35>
mov    0x2e7a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <setusershell@plt>
mov    $0x0,%al
call   1040 <getusershell@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11b2 <smbftpd_valid_shell+0x72>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11ad <smbftpd_valid_shell+0x6d>
jmp    11b2 <smbftpd_valid_shell+0x72>
jmp    117c <smbftpd_valid_shell+0x3c>
mov    $0x0,%al
call   1060 <endusershell@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11d0 <smbftpd_valid_shell+0x90>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <smbftpd_valid_shell+0x97>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smbftpd_valid_shell>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1151 <smbftpd_valid_shell+0x11>
mov    %rdi,%r14
cmpb   $0x0,(%rdi)
jne    115b <smbftpd_valid_shell+0x1b>
mov    0x2e90(%rip),%rax
mov    (%rax),%r14
xor    %eax,%eax
call   1030 <setusershell@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getusershell@plt>
mov    %rax,%rbx
test   %rax,%rax
je     118f <smbftpd_valid_shell+0x4f>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1170 <smbftpd_valid_shell+0x30>
xor    %eax,%eax
call   1060 <endusershell@plt>
cmp    $0x1,%rbx
sbb    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@_PATH_BSHELL = global i8* null
define i32 @smbftpd_valid_shell(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7, %1
%13 = load i8*, i8** @_PATH_BSHELL
store i8* %13, i8** %3
br label %14
14: ; preds = %12, %7
%15 = call i32 (...) @setusershell()
br label %16
16: ; preds = %25, %14
%17 = call i8* (...) @getusershell()
store i8* %17, i8** %4
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i8*, i8** %4
%21 = load i8*, i8** %3
%22 = call i64 @strcmp(i8* %20, i8* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
br label %26
25: ; preds = %19
br label %16
26: ; preds = %24, %16
%27 = call i32 (...) @endusershell()
%28 = load i8*, i8** %4
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 -1, i32* %2
br label %32
31: ; preds = %26
store i32 0, i32* %2
br label %32
32: ; preds = %31, %30
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@_PATH_BSHELL = global i8* null
define i32 @smbftpd_valid_shell(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3, %1
%7 = load i8*, i8** @_PATH_BSHELL
br label %8
8: ; preds = %6, %3
%9 = phi i8* [ %7, %6 ], [ %0, %3 ]
%10 = tail call i32 (...) @setusershell()
br label %11
11: ; preds = %14, %8
%12 = tail call i8* (...) @getusershell()
%13 = icmp eq i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = tail call i64 @strcmp(i8* %12, i8* %9)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %11
17: ; preds = %14, %11
%18 = tail call i32 (...) @endusershell()
%19 = sext i1 %13 to i32
ret i32 %19
}