#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 */
size_t strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char const *, size_t const);
const char *UnprefixedCustomShell(const char *shell) {
  if (shell == NULL) {
    return NULL;
  }
  const char *prefix = "SHELL=";
  const size_t len = strlen(prefix);
  if (!strncmp(shell, prefix, len)) {
    return shell + len;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<UnprefixedCustomShell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <UnprefixedCustomShell+0x24>
movq   $0x0,-0x8(%rbp)
jmp    118f <UnprefixedCustomShell+0x6f>
lea    0xeb5(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1187 <UnprefixedCustomShell+0x67>
mov    -0x10(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    118f <UnprefixedCustomShell+0x6f>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UnprefixedCustomShell>:
test   %rdi,%rdi
je     113a <UnprefixedCustomShell+0x2a>
push   %rbx
mov    %rdi,%rbx
lea    0xee0(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
mov    %eax,%ecx
add    $0x6,%rbx
xor    %eax,%eax
test   %ecx,%ecx
cmove  %rbx,%rax
pop    %rbx
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [7 x i8] c"SHELL=\00"
define i8* @UnprefixedCustomShell(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i8* null, i8** %2
br label %22
9: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %4
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %5
%12 = load i8*, i8** %3
%13 = load i8*, i8** %4
%14 = load i64, i64* %5
%15 = call i32 @strncmp(i8* %12, i8* %13, i64 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %9
%18 = load i8*, i8** %3
%19 = load i64, i64* %5
%20 = getelementptr inbounds i8, i8* %18, i64 %19
store i8* %20, i8** %2
br label %22
21: ; preds = %9
store i8* null, i8** %2
br label %22
22: ; preds = %21, %17, %8
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
@.str = [7 x i8] c"SHELL=\00"
define i8* @UnprefixedCustomShell(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %8, label %3
3: ; preds = %1
%4 = tail call i32 @strncmp(i8* %0, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 6)
%5 = icmp eq i32 %4, 0
%6 = getelementptr inbounds i8, i8* %0, i64 6
%7 = select i1 %5, i8* %6, i8* null
br label %8
8: ; preds = %1, %3
%9 = phi i8* [ %7, %3 ], [ null, %1 ]
ret i8* %9
}