#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 O_CREAT;
int O_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ write(int, char *, int);
void cycle_watchers(void) {
  int fd;
  char zero[2];
  fd = open("/run/suspend/watching", O_RDWR | O_CREAT, 0640);
  if (fd < 0)
    return;
  rename("/run/suspend/watching-next", "/run/suspend/watching");
  zero[0] = zero[1] = 0;
  write(fd, zero, 2);
  close(fd);
}


x86 assembly (clang, -O0):
<cycle_watchers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
mov    0x2ea0(%rip),%rax
or     (%rax),%esi
lea    0xe9f(%rip),%rdi
mov    $0x1a0,%edx
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    117d <cycle_watchers+0x3d>
jmp    11b1 <cycle_watchers+0x71>
lea    0xe92(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1060 <rename@plt>
movb   $0x0,-0x5(%rbp)
movb   $0x0,-0x6(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x6(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cycle_watchers>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e94(%rip),%rax
mov    0x2ea5(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xea2(%rip),%rdi
mov    $0x1a0,%edx
call   1050 <open@plt>
test   %eax,%eax
js     11a5 <cycle_watchers+0x65>
mov    %eax,%ebx
lea    0xea1(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1060 <rename@plt>
movw   $0x0,0xe(%rsp)
lea    0xe(%rsp),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %ebx,%edi
add    $0x10,%rsp
pop    %rbx
jmp    1040 <close@plt>
add    $0x10,%rsp
pop    %rbx
ret

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

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