#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*/ LOCK_EX;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ flock(int, int /*<<< orphan*/);
int open(char *, int, int);
int write(int, char *, int);
void alert_watchers(void) {
  int fd;
  char zero = 0;
  fd = open("/run/suspend/watching-next", O_RDWR | O_CREAT | O_TRUNC, 0640);
  if (fd < 0)
    return;
  close(fd);
  fd = open("/run/suspend/watching", O_RDWR | O_CREAT | O_TRUNC, 0640);
  if (fd < 0)
    return;
  if (write(fd, &zero, 1) != 1)
    return;
  flock(fd, LOCK_EX);
  close(fd);
}


x86 assembly (clang, -O0):
<alert_watchers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0x0,-0x5(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
mov    0x2e9c(%rip),%rax
or     (%rax),%esi
mov    0x2e8b(%rip),%rax
or     (%rax),%esi
lea    0xe92(%rip),%rdi
mov    $0x1a0,%edx
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    118a <alert_watchers+0x4a>
jmp    1208 <alert_watchers+0xc8>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
mov    0x2e56(%rip),%rax
or     (%rax),%esi
mov    0x2e45(%rip),%rax
or     (%rax),%esi
lea    0xe67(%rip),%rdi
mov    $0x1a0,%edx
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11d0 <alert_watchers+0x90>
jmp    1208 <alert_watchers+0xc8>
mov    -0x4(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     11ef <alert_watchers+0xaf>
jmp    1208 <alert_watchers+0xc8>
mov    -0x4(%rbp),%edi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
call   1060 <flock@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alert_watchers>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e88(%rip),%r14
mov    0x2ea1(%rip),%rbx
mov    (%rbx),%esi
or     (%r14),%esi
movb   $0x0,0xf(%rsp)
mov    0x2e88(%rip),%r15
or     (%r15),%esi
lea    0xe8e(%rip),%rdi
mov    $0x1a0,%edx
call   1050 <open@plt>
test   %eax,%eax
js     11dc <alert_watchers+0x9c>
mov    %eax,%edi
call   1040 <close@plt>
mov    (%rbx),%esi
or     (%r14),%esi
or     (%r15),%esi
lea    0xe85(%rip),%rdi
mov    $0x1a0,%edx
call   1050 <open@plt>
test   %eax,%eax
js     11dc <alert_watchers+0x9c>
mov    %eax,%ebx
lea    0xf(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    11dc <alert_watchers+0x9c>
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1060 <flock@plt>
mov    %ebx,%edi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <close@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"/run/suspend/watching-next\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [22 x i8] c"/run/suspend/watching\00"
@LOCK_EX = global i32 0
define void @alert_watchers() {
%1 = alloca i32
%2 = alloca i8
store i8 0, i8* %2
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_CREAT
%5 = or i32 %3, %4
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %5, %6
%8 = call i32 @open(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %7, i32 416)
store i32 %8, i32* %1
%9 = load i32, i32* %1
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %0
br label %35
12: ; preds = %0
%13 = load i32, i32* %1
%14 = call i32 @close(i32 %13)
%15 = load i32, i32* @O_RDWR
%16 = load i32, i32* @O_CREAT
%17 = or i32 %15, %16
%18 = load i32, i32* @O_TRUNC
%19 = or i32 %17, %18
%20 = call i32 @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 416)
store i32 %20, i32* %1
%21 = load i32, i32* %1
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %12
br label %35
24: ; preds = %12
%25 = load i32, i32* %1
%26 = call i32 @write(i32 %25, i8* %2, i32 1)
%27 = icmp ne i32 %26, 1
br i1 %27, label %28, label %29
28: ; preds = %24
br label %35
29: ; preds = %24
%30 = load i32, i32* %1
%31 = load i32, i32* @LOCK_EX
%32 = call i32 @flock(i32 %30, i32 %31)
%33 = load i32, i32* %1
%34 = call i32 @close(i32 %33)
br label %35
35: ; preds = %29, %28, %23, %11
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"/run/suspend/watching-next\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [22 x i8] c"/run/suspend/watching\00"
@LOCK_EX = global i32 0
define void @alert_watchers() {
%1 = alloca i8
store i8 0, i8* %1
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @O_TRUNC
%6 = or i32 %4, %5
%7 = tail call i32 @open(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %6, i32 416)
%8 = icmp slt i32 %7, 0
br i1 %8, label %25, label %9
9: ; preds = %0
%10 = tail call i32 @close(i32 %7)
%11 = load i32, i32* @O_RDWR
%12 = load i32, i32* @O_CREAT
%13 = or i32 %12, %11
%14 = load i32, i32* @O_TRUNC
%15 = or i32 %13, %14
%16 = tail call i32 @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 416)
%17 = icmp slt i32 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %9
%19 = call i32 @write(i32 %16, i8* %1, i32 1)
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i32, i32* @LOCK_EX
%23 = tail call i32 @flock(i32 %16, i32 %22)
%24 = tail call i32 @close(i32 %16)
br label %25
25: ; preds = %18, %9, %0, %21
ret void
}