#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_size;
  int /*<<< orphan*/ st_mode;
};
typedef int /*<<< orphan*/ path;

/* Variables and functions */
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ swap_path(char *, int);
unsigned swap_available(void) {
  char path[256];
  struct stat buf;
  if (!swap_path(path, sizeof(path)))
    return 0;
  if (stat(path, &buf))
    return 0;
  if (!S_ISREG(buf.st_mode))
    return 0;
  return (unsigned)(buf.st_size);
}


x86 assembly (clang, -O0):
<swap_available>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   1050 <swap_path@plt>
cmp    $0x0,%eax
jne    1161 <swap_available+0x31>
movl   $0x0,-0x4(%rbp)
jmp    11b3 <swap_available+0x83>
lea    -0x110(%rbp),%rdi
lea    -0x118(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
je     118a <swap_available+0x5a>
movl   $0x0,-0x4(%rbp)
jmp    11b3 <swap_available+0x83>
mov    -0x114(%rbp),%edi
call   1040 <S_ISREG@plt>
cmp    $0x0,%eax
jne    11aa <swap_available+0x7a>
movl   $0x0,-0x4(%rbp)
jmp    11b3 <swap_available+0x83>
mov    -0x118(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap_available>:
push   %rbx
sub    $0x110,%rsp
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
call   1050 <swap_path@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     1172 <swap_available+0x42>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
test   %rax,%rax
jne    1172 <swap_available+0x42>
mov    0xc(%rsp),%edi
call   1040 <S_ISREG@plt>
test   %eax,%eax
je     1172 <swap_available+0x42>
mov    0x8(%rsp),%ebx
mov    %ebx,%eax
add    $0x110,%rsp
pop    %rbx
ret

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

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