#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 S_IFDIR;
int S_IFMT;
scalar_t__ stat(char const *, struct stat *);
int is_local_file(const char *filename) {
  struct stat buf;
  if (stat(filename, &buf) == 0) {
    if (buf.st_mode & S_IFDIR) {
      return 0;
    }
    if (buf.st_mode & S_IFMT) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<is_local_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
jne    117a <is_local_file+0x6a>
mov    -0x18(%rbp),%eax
mov    0x2e93(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1154 <is_local_file+0x44>
movl   $0x0,-0x4(%rbp)
jmp    1181 <is_local_file+0x71>
mov    -0x18(%rbp),%eax
mov    0x2e82(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1175 <is_local_file+0x65>
movl   $0x1,-0x4(%rbp)
jmp    1181 <is_local_file+0x71>
jmp    117a <is_local_file+0x6a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_local_file>:
push   %rax
mov    %rsp,%rsi
call   1030 <stat@plt>
test   %rax,%rax
je     1122 <is_local_file+0x12>
xor    %eax,%eax
jmp    1142 <is_local_file+0x32>
mov    (%rsp),%ecx
mov    0x2ea4(%rip),%rdx
xor    %eax,%eax
test   %ecx,(%rdx)
jne    1142 <is_local_file+0x32>
mov    0x2ea7(%rip),%rdx
mov    $0x1,%eax
test   %ecx,(%rdx)
je     111e <is_local_file+0xe>
pop    %rcx
ret

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

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