#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 */
int /*<<< orphan*/ MOUNTED;
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ close(int);
scalar_t__ mtab_is_a_symlink();
int open(int /*<<< orphan*/, int, int);
int mtab_is_writable() {
  int fd;
  if (mtab_is_a_symlink())
    return 0;
  fd = open(MOUNTED, O_RDWR | O_CREAT, 0644);
  if (fd >= 0) {
    close(fd);
    return 1;
  } else
    return 0;
}


x86 assembly (clang, -O0):
<mtab_is_writable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <mtab_is_a_symlink@plt>
cmp    $0x0,%rax
je     1155 <mtab_is_writable+0x25>
movl   $0x0,-0x4(%rbp)
jmp    11a2 <mtab_is_writable+0x72>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
mov    0x2e8a(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     119b <mtab_is_writable+0x6b>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a2 <mtab_is_writable+0x72>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mtab_is_writable>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <mtab_is_a_symlink@plt>
test   %rax,%rax
jne    1174 <mtab_is_writable+0x44>
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
mov    0x2e91(%rip),%rax
mov    0x2ea2(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1a4,%edx
call   1050 <open@plt>
test   %eax,%eax
js     1174 <mtab_is_writable+0x44>
mov    %eax,%edi
call   1040 <close@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@MOUNTED = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
define i32 @mtab_is_writable() {
%1 = alloca i32
%2 = alloca i32
%3 = call i64 (...) @mtab_is_a_symlink()
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %6
5: ; preds = %0
store i32 0, i32* %1
br label %18
6: ; preds = %0
%7 = load i32, i32* @MOUNTED
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_CREAT
%10 = or i32 %8, %9
%11 = call i32 @open(i32 %7, i32 %10, i32 420)
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %6
%15 = load i32, i32* %2
%16 = call i32 @close(i32 %15)
store i32 1, i32* %1
br label %18
17: ; preds = %6
store i32 0, i32* %1
br label %18
18: ; preds = %17, %14, %5
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@MOUNTED = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
define i32 @mtab_is_writable() {
%1 = tail call i64 (...) @mtab_is_a_symlink()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %12
3: ; preds = %0
%4 = load i32, i32* @MOUNTED
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_CREAT
%7 = or i32 %6, %5
%8 = tail call i32 @open(i32 %4, i32 %7, i32 420)
%9 = icmp sgt i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 @close(i32 %8)
br label %12
12: ; preds = %3, %0, %10
%13 = phi i32 [ 1, %10 ], [ 0, %0 ], [ 0, %3 ]
ret i32 %13
}