#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 /*<<< orphan*/ endusershell();
char *getusershell();
int /*<<< orphan*/ setusershell();
scalar_t__ strcmp(char *, char *);
char *strrchr(char *, char);
int ok_shell(char *name) {
  char *p, *sh;
  setusershell();
  while ((sh = getusershell())) {
    if (!strcmp(name, sh)) {
      endusershell();
      return (1);
    }
    if ((p = strrchr(sh, '/')) && strcmp(name, p + 1) == 0) {
      endusershell();
      return (1);
    }
  }
  endusershell();
  return (0);
}


x86 assembly (clang, -O0):
<ok_shell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <setusershell@plt>
mov    $0x0,%al
call   1050 <getusershell@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11f1 <ok_shell+0xa1>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11a2 <ok_shell+0x52>
mov    $0x0,%al
call   1070 <endusershell@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ff <ok_shell+0xaf>
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11ec <ok_shell+0x9c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11ec <ok_shell+0x9c>
mov    $0x0,%al
call   1070 <endusershell@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ff <ok_shell+0xaf>
jmp    1163 <ok_shell+0x13>
mov    $0x0,%al
call   1070 <endusershell@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ok_shell>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <setusershell@plt>
xor    %eax,%eax
call   1050 <getusershell@plt>
test   %rax,%rax
je     11cc <ok_shell+0x7c>
mov    %rax,%rbx
jmp    1191 <ok_shell+0x41>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <getusershell@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11cc <ok_shell+0x7c>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11cc <ok_shell+0x7c>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     1180 <ok_shell+0x30>
add    $0x1,%rax
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1180 <ok_shell+0x30>
xor    %eax,%eax
call   1070 <endusershell@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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