#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISREG(int /*<<< orphan*/);
int const endswith(char *, char *, int, int);
int stat(char *, struct stat *);
const int match_sufix(char *path, char *file, char *name) {
  struct stat s;
  int err = stat(path, &s);
  if (err != 1 && S_ISREG(s.st_mode)) {
    return endswith(name, file, -1, -1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<match_sufix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <stat@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
je     118c <match_sufix+0x5c>
mov    -0x28(%rbp),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     118c <match_sufix+0x5c>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xffffffff,%ecx
mov    %ecx,%edx
call   1030 <endswith@plt>
mov    %eax,-0x4(%rbp)
jmp    1193 <match_sufix+0x63>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_sufix>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rsp,%rsi
call   1040 <stat@plt>
cmp    $0x1,%eax
je     1170 <match_sufix+0x40>
mov    (%rsp),%edi
call   1050 <S_ISREG@plt>
test   %rax,%rax
je     1170 <match_sufix+0x40>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0xffffffff,%edx
mov    $0xffffffff,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <endswith@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @match_sufix(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.stat
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %5
%11 = call i32 @stat(i8* %10, %struct.stat* %8)
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %23
14: ; preds = %3
%15 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i64 @S_ISREG(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i8*, i8** %7
%21 = load i8*, i8** %6
%22 = call i32 @endswith(i8* %20, i8* %21, i32 -1, i32 -1)
store i32 %22, i32* %4
br label %24
23: ; preds = %14, %3
store i32 0, i32* %4
br label %24
24: ; preds = %23, %19
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @match_sufix(i8* nocapture %0, i8* %1, i8* %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = call i32 @stat(i8* %0, %struct.stat* %4)
%7 = icmp eq i32 %6, 1
br i1 %7, label %15, label %8
8: ; preds = %3
%9 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i64 @S_ISREG(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = tail call i32 @endswith(i8* %2, i8* %1, i32 -1, i32 -1)
br label %15
15: ; preds = %3, %8, %13
%16 = phi i32 [ %14, %13 ], [ 0, %8 ], [ 0, %3 ]
ret i32 %16
}