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

/* Variables and functions */
scalar_t__ EBUSY;
scalar_t__ EINVAL;
unsigned int FIFREEZE;
unsigned int FITHAW;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int ioctl(int, unsigned int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int vss_do_freeze(char *dir, unsigned int cmd) {
  int ret, fd = open(dir, O_RDONLY);
  if (fd < 0) {
    return 1;
  }
  ret = ioctl(fd, cmd, 0);
  if (ret) {
    if ((cmd == FIFREEZE && errno == EBUSY) ||
        (cmd == FITHAW && errno == EINVAL)) {
      close(fd);
      return 0;
    }
  }
  close(fd);
  return !!ret;
}


x86 assembly (clang, -O0):
<vss_do_freeze>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    116a <vss_do_freeze+0x3a>
movl   $0x1,-0x4(%rbp)
jmp    1210 <vss_do_freeze+0xe0>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11f5 <vss_do_freeze+0xc5>
mov    -0x14(%rbp),%eax
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%eax
jne    11b0 <vss_do_freeze+0x80>
mov    0x2e33(%rip),%rax
mov    (%rax),%rax
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%rax
je     11dc <vss_do_freeze+0xac>
mov    -0x14(%rbp),%eax
mov    0x2df6(%rip),%rcx
cmp    (%rcx),%eax
jne    11f0 <vss_do_freeze+0xc0>
mov    0x2e07(%rip),%rax
mov    (%rax),%rax
mov    0x2df5(%rip),%rcx
cmp    (%rcx),%rax
jne    11f0 <vss_do_freeze+0xc0>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1210 <vss_do_freeze+0xe0>
jmp    11f5 <vss_do_freeze+0xc5>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vss_do_freeze>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
js     11b6 <vss_do_freeze+0x86>
mov    %eax,%ebx
mov    %eax,%edi
mov    %ebp,%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
test   %eax,%eax
je     11a5 <vss_do_freeze+0x75>
mov    0x2e81(%rip),%rcx
cmp    %ebp,(%rcx)
jne    1179 <vss_do_freeze+0x49>
mov    0x2e66(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e4c(%rip),%rdx
cmp    (%rdx),%rcx
je     119a <vss_do_freeze+0x6a>
mov    0x2e30(%rip),%rcx
cmp    %ebp,(%rcx)
jne    11a5 <vss_do_freeze+0x75>
mov    0x2e45(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e33(%rip),%rdx
cmp    (%rdx),%rcx
jne    11a5 <vss_do_freeze+0x75>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %ebp,%ebp
jmp    11bb <vss_do_freeze+0x8b>
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
mov    %ebx,%edi
call   1040 <close@plt>
jmp    11bb <vss_do_freeze+0x8b>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@FIFREEZE = global i32 0
@errno = global i64 0
@EBUSY = global i64 0
@FITHAW = global i32 0
@EINVAL = global i64 0
define i32 @vss_do_freeze(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %3
br label %48
14: ; preds = %2
%15 = load i32, i32* %7
%16 = load i32, i32* %5
%17 = call i32 @ioctl(i32 %15, i32 %16, i32 0)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %40
20: ; preds = %14
%21 = load i32, i32* %5
%22 = load i32, i32* @FIFREEZE
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i64, i64* @errno
%26 = load i64, i64* @EBUSY
%27 = icmp eq i64 %25, %26
br i1 %27, label %36, label %28
28: ; preds = %24, %20
%29 = load i32, i32* %5
%30 = load i32, i32* @FITHAW
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %39
32: ; preds = %28
%33 = load i64, i64* @errno
%34 = load i64, i64* @EINVAL
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %39
36: ; preds = %32, %24
%37 = load i32, i32* %7
%38 = call i32 @close(i32 %37)
store i32 0, i32* %3
br label %48
39: ; preds = %32, %28
br label %40
40: ; preds = %39, %14
%41 = load i32, i32* %7
%42 = call i32 @close(i32 %41)
%43 = load i32, i32* %6
%44 = icmp ne i32 %43, 0
%45 = xor i1 %44, true
%46 = xor i1 %45, true
%47 = zext i1 %46 to i32
store i32 %47, i32* %3
br label %48
48: ; preds = %40, %36, %13
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@FIFREEZE = global i32 0
@errno = global i64 0
@EBUSY = global i64 0
@FITHAW = global i32 0
@EINVAL = global i64 0
define i32 @vss_do_freeze(i8* nocapture %0, i32 %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %28, label %6
6: ; preds = %2
%7 = tail call i32 @ioctl(i32 %4, i32 %1, i32 0)
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %6
%10 = load i32, i32* @FIFREEZE
%11 = icmp eq i32 %10, %1
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i64, i64* @errno
%14 = load i64, i64* @EBUSY
%15 = icmp eq i64 %13, %14
br i1 %15, label %23, label %16
16: ; preds = %12, %9
%17 = load i32, i32* @FITHAW
%18 = icmp eq i32 %17, %1
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i64, i64* @errno
%21 = load i64, i64* @EINVAL
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %19, %12
%24 = tail call i32 @close(i32 %4)
br label %28
25: ; preds = %16, %19, %6
%26 = tail call i32 @close(i32 %4)
%27 = zext i1 %8 to i32
br label %28
28: ; preds = %2, %25, %23
%29 = phi i32 [ 0, %23 ], [ %27, %25 ], [ 1, %2 ]
ret i32 %29
}