#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 */
scalar_t__ stricmp(char *, char *);
char *strrchr(char const *, char);
int is_exec(const char *name) {
  char *p = strrchr(name, '.');
  return (p != NULL &&
          ((stricmp(p, ".exe") == 0) || (stricmp(p, ".com") == 0) ||
           (stricmp(p, ".bat") == 0) || (stricmp(p, ".cmd") == 0)));
}


x86 assembly (clang, -O0):
<is_exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
je     11d4 <is_exec+0xb4>
mov    -0x10(%rbp),%rdi
lea    0xea7(%rip),%rsi
call   1030 <stricmp@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x12(%rbp)
je     11ce <is_exec+0xae>
mov    -0x10(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1030 <stricmp@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x12(%rbp)
je     11ce <is_exec+0xae>
mov    -0x10(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1030 <stricmp@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x12(%rbp)
je     11ce <is_exec+0xae>
mov    -0x10(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1030 <stricmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_exec>:
push   %rbp
push   %rbx
push   %rax
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1190 <is_exec+0x70>
mov    %rax,%rbx
lea    0xec4(%rip),%rsi
mov    %rax,%rdi
call   1030 <stricmp@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1192 <is_exec+0x72>
lea    0xeb0(%rip),%rsi
mov    %rbx,%rdi
call   1030 <stricmp@plt>
test   %rax,%rax
je     1192 <is_exec+0x72>
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
call   1030 <stricmp@plt>
test   %rax,%rax
je     1192 <is_exec+0x72>
lea    0xe92(%rip),%rsi
mov    %rbx,%rdi
call   1030 <stricmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
jmp    1192 <is_exec+0x72>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c".exe\00"
@.str.1 = [5 x i8] c".com\00"
@.str.2 = [5 x i8] c".bat\00"
@.str.3 = [5 x i8] c".cmd\00"
define i32 @is_exec(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i8* @strrchr(i8* %4, i8 signext 46)
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %26
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i64 @stricmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %24, label %12
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = call i64 @stricmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = call i64 @stricmp(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = load i8*, i8** %3
%22 = call i64 @stricmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br label %24
24: ; preds = %20, %16, %12, %8
%25 = phi i1 [ true, %16 ], [ true, %12 ], [ true, %8 ], [ %23, %20 ]
br label %26
26: ; preds = %24, %1
%27 = phi i1 [ false, %1 ], [ %25, %24 ]
%28 = zext i1 %27 to i32
ret i32 %28
}

LLVM IR (-O2):
@.str = [5 x i8] c".exe\00"
@.str.1 = [5 x i8] c".com\00"
@.str.2 = [5 x i8] c".bat\00"
@.str.3 = [5 x i8] c".cmd\00"
define i32 @is_exec(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%3 = icmp eq i8* %2, null
br i1 %3, label %17, label %4
4: ; preds = %1
%5 = tail call i64 @stricmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %4
%8 = tail call i64 @stricmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %7
%11 = tail call i64 @stricmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = tail call i64 @stricmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %4, %7, %10, %13, %1
%18 = phi i32 [ 0, %1 ], [ 1, %10 ], [ 1, %7 ], [ 1, %4 ], [ %16, %13 ]
ret i32 %18
}