#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int set_wakeup_count(int count) {
  int fd;
  char buf[20];
  int n;
  if (count < 0)
    return 1;
  fd = open("/sys/power/wakeup_count", O_RDWR);
  if (fd < 0)
    return 1;
  snprintf(buf, sizeof(buf), "%d", count);
  n = write(fd, buf, strlen(buf));
  close(fd);
  if (n < 0)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<set_wakeup_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1171 <set_wakeup_count+0x21>
movl   $0x1,-0x4(%rbp)
jmp    1204 <set_wakeup_count+0xb4>
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
lea    0xe7f(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    119f <set_wakeup_count+0x4f>
movl   $0x1,-0x4(%rbp)
jmp    1204 <set_wakeup_count+0xb4>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x14,%esi
lea    0xe66(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
cmpl   $0x0,-0x24(%rbp)
jge    11fd <set_wakeup_count+0xad>
movl   $0x0,-0x4(%rbp)
jmp    1204 <set_wakeup_count+0xb4>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_wakeup_count>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    $0x1,%ebx
test   %edi,%edi
js     11bc <set_wakeup_count+0x6c>
mov    %edi,%ebp
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
lea    0xe8d(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11bc <set_wakeup_count+0x6c>
mov    %eax,%r14d
lea    0xe92(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x14,%esi
mov    %ebp,%ecx
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%ebx
mov    %r14d,%edi
call   1060 <close@plt>
not    %ebx
shr    $0x1f,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"/sys/power/wakeup_count\00"
@O_RDWR = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define i32 @set_wakeup_count(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [20 x i8]
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 1, i32* %2
br label %31
10: ; preds = %1
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10
store i32 1, i32* %2
br label %31
16: ; preds = %10
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%18 = load i32, i32* %3
%19 = call i32 @snprintf(i8* %17, i32 20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %4
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = call i32 @write(i32 %20, i8* %21, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %4
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* %6
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %16
store i32 0, i32* %2
br label %31
30: ; preds = %16
store i32 1, i32* %2
br label %31
31: ; preds = %30, %29, %15, %9
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@.str = [24 x i8] c"/sys/power/wakeup_count\00"
@O_RDWR = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define i32 @set_wakeup_count(i32 %0) {
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%4 = icmp slt i32 %0, 0
br i1 %4, label %16, label %5
5: ; preds = %1
%6 = load i32, i32* @O_RDWR
%7 = tail call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %5
%10 = call i32 @snprintf(i8* %3, i32 20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%11 = call i32 @strlen(i8* %3)
%12 = call i32 @write(i32 %7, i8* %3, i32 %11)
%13 = call i32 @close(i32 %7)
%14 = xor i32 %12, -1
%15 = lshr i32 %14, 31
br label %16
16: ; preds = %9, %5, %1
%17 = phi i32 [ 1, %1 ], [ 1, %5 ], [ %15, %9 ]
ret i32 %17
}