#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 st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ S_ISREG(int);
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
int stat(char const *, struct stat *);
scalar_t__ strstr(char const *, char *);
int poptSaneFile(const char *fn) {
  struct stat sb;
  if (fn == NULL || strstr(fn, ".rpmnew") || strstr(fn, ".rpmsave"))
    return 0;
  if (stat(fn, &sb) == -1)
    return 0;
  if (!S_ISREG(sb.st_mode))
    return 0;
  if (sb.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<poptSaneFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117b <poptSaneFile+0x4b>
mov    -0x10(%rbp),%rdi
lea    0xeae(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
jne    117b <poptSaneFile+0x4b>
mov    -0x10(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     1187 <poptSaneFile+0x57>
movl   $0x0,-0x4(%rbp)
jmp    1202 <poptSaneFile+0xd2>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0xffffffff,%eax
jne    11a9 <poptSaneFile+0x79>
movl   $0x0,-0x4(%rbp)
jmp    1202 <poptSaneFile+0xd2>
mov    -0x18(%rbp),%edi
call   1040 <S_ISREG@plt>
cmp    $0x0,%eax
jne    11c6 <poptSaneFile+0x96>
movl   $0x0,-0x4(%rbp)
jmp    1202 <poptSaneFile+0xd2>
mov    -0x18(%rbp),%eax
mov    0x2e10(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2dff(%rip),%rdx
or     (%rdx),%ecx
mov    0x2e06(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11fb <poptSaneFile+0xcb>
movl   $0x0,-0x4(%rbp)
jmp    1202 <poptSaneFile+0xd2>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poptSaneFile>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     11a3 <poptSaneFile+0x73>
mov    %rdi,%rbx
lea    0xebc(%rip),%rsi
call   1050 <strstr@plt>
test   %rax,%rax
jne    11a3 <poptSaneFile+0x73>
lea    0xeb3(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
jne    11a3 <poptSaneFile+0x73>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <stat@plt>
cmp    $0xffffffff,%eax
je     11a3 <poptSaneFile+0x73>
mov    (%rsp),%ebx
mov    %ebx,%edi
call   1040 <S_ISREG@plt>
test   %eax,%eax
je     11a3 <poptSaneFile+0x73>
mov    0x2e59(%rip),%rax
mov    0x2e4a(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e4f(%rip),%rax
or     (%rax),%ecx
xor    %ebp,%ebp
test   %ebx,%ecx
sete   %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [8 x i8] c".rpmnew\00"
@.str.1 = [9 x i8] c".rpmsave\00"
@S_IXUSR = global i32 0
@S_IXGRP = global i32 0
@S_IXOTH = global i32 0
define i32 @poptSaneFile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %15, label %7
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = call i64 @strstr(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%10 = icmp ne i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = call i64 @strstr(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11, %7, %1
store i32 0, i32* %2
br label %39
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = call i32 @stat(i8* %17, %struct.stat* %4)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 0, i32* %2
br label %39
21: ; preds = %16
%22 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @S_ISREG(i32 %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %21
store i32 0, i32* %2
br label %39
27: ; preds = %21
%28 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%29 = load i32, i32* %28
%30 = load i32, i32* @S_IXUSR
%31 = load i32, i32* @S_IXGRP
%32 = or i32 %30, %31
%33 = load i32, i32* @S_IXOTH
%34 = or i32 %32, %33
%35 = and i32 %29, %34
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %27
store i32 0, i32* %2
br label %39
38: ; preds = %27
store i32 1, i32* %2
br label %39
39: ; preds = %38, %37, %26, %20, %15
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [8 x i8] c".rpmnew\00"
@.str.1 = [9 x i8] c".rpmsave\00"
@S_IXUSR = global i32 0
@S_IXGRP = global i32 0
@S_IXOTH = global i32 0
define i32 @poptSaneFile(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %28, label %5
5: ; preds = %1
%6 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %28
8: ; preds = %5
%9 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = call i32 @stat(i8* %0, %struct.stat* %2)
%13 = icmp eq i32 %12, -1
br i1 %13, label %28, label %14
14: ; preds = %11
%15 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%16 = load i32, i32* %15
%17 = tail call i32 @S_ISREG(i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %14
%20 = load i32, i32* @S_IXUSR
%21 = load i32, i32* @S_IXGRP
%22 = or i32 %21, %20
%23 = load i32, i32* @S_IXOTH
%24 = or i32 %22, %23
%25 = and i32 %24, %16
%26 = icmp eq i32 %25, 0
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %19, %14, %11, %1, %5, %8
%29 = phi i32 [ 0, %8 ], [ 0, %5 ], [ 0, %1 ], [ 0, %11 ], [ 0, %14 ], [ %27, %19 ]
ret i32 %29
}