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

/* Variables and functions */
scalar_t__ strcmp(char const *, char const *);
size_t strlen(char const *);
int isSourceFile(const char *path) {
  const char *suffixes[] = {
      ".h",
      ".c",
      ".cpp",
  };
  size_t num_suffixes = sizeof(suffixes) / sizeof(suffixes[0]);
  size_t n = strlen(path);
  size_t i;
  for (i = 0; i < num_suffixes; i++) {
    size_t m = strlen(suffixes[i]);
    if (n >= m && strcmp(path + n - m, suffixes[i]) == 0) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<isSourceFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ccd(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2cca(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2cc7(%rip),%rax
mov    %rax,-0x20(%rbp)
movq   $0x3,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    11e3 <isSourceFile+0xc3>
mov    -0x48(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x50(%rbp),%rax
jb     11cd <isSourceFile+0xad>
mov    -0x10(%rbp),%rdi
add    -0x40(%rbp),%rdi
xor    %eax,%eax
sub    -0x50(%rbp),%rax
add    %rax,%rdi
mov    -0x48(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11cd <isSourceFile+0xad>
movl   $0x1,-0x4(%rbp)
jmp    11ea <isSourceFile+0xca>
jmp    11d2 <isSourceFile+0xb2>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    116a <isSourceFile+0x4a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isSourceFile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0x2,%rax
jae    113a <isSourceFile+0x1a>
xor    %r14d,%r14d
jmp    1190 <isSourceFile+0x70>
mov    %rax,%rbp
add    %rax,%rbx
lea    -0x2(%rbx),%r15
lea    0xeb5(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     1190 <isSourceFile+0x70>
lea    0xe9e(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1190 <isSourceFile+0x70>
cmp    $0x4,%rbp
jb     1135 <isSourceFile+0x15>
add    $0xfffffffffffffffc,%rbx
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1135 <isSourceFile+0x15>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c".h\00"
@.str.1 = [3 x i8] c".c\00"
@.str.2 = [5 x i8] c".cpp\00"
@__const.isSourceFile.suffixes = [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0)]
define i32 @isSourceFile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [3 x i8*]
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %3
%9 = bitcast [3 x i8*]* %4 to i8*
store i64 3, i64* %5
%10 = load i8*, i8** %3
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %6
store i64 0, i64* %7
br label %12
12: ; preds = %38, %1
%13 = load i64, i64* %7
%14 = load i64, i64* %5
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %41
16: ; preds = %12
%17 = load i64, i64* %7
%18 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 %17
%19 = load i8*, i8** %18
%20 = call i64 @strlen(i8* %19)
store i64 %20, i64* %8
%21 = load i64, i64* %6
%22 = load i64, i64* %8
%23 = icmp uge i64 %21, %22
br i1 %23, label %24, label %37
24: ; preds = %16
%25 = load i8*, i8** %3
%26 = load i64, i64* %6
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%28 = load i64, i64* %8
%29 = sub i64 0, %28
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i64, i64* %7
%32 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 %31
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i8* %30, i8* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %24
store i32 1, i32* %2
br label %42
37: ; preds = %24, %16
br label %38
38: ; preds = %37
%39 = load i64, i64* %7
%40 = add i64 %39, 1
store i64 %40, i64* %7
br label %12
41: ; preds = %12
store i32 0, i32* %2
br label %42
42: ; preds = %41, %36
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
@.str = [3 x i8] c".h\00"
@.str.1 = [3 x i8] c".c\00"
@.str.2 = [5 x i8] c".cpp\00"
define i32 @isSourceFile(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = getelementptr inbounds i8, i8* %0, i64 %2
%4 = icmp ult i64 %2, 2
br i1 %4, label %19, label %5
5: ; preds = %1
%6 = getelementptr inbounds i8, i8* %3, i64 -2
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %20, label %9
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %3, i64 -2
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %9
%14 = icmp ult i64 %2, 4
br i1 %14, label %19, label %15
15: ; preds = %13
%16 = getelementptr inbounds i8, i8* %3, i64 -4
%17 = tail call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %1, %15, %13
br label %20
20: ; preds = %19, %15, %9, %5
%21 = phi i32 [ 1, %5 ], [ 1, %9 ], [ 1, %15 ], [ 0, %19 ]
ret i32 %21
}