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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
char *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
int may_wakeup(const char *devname) {
  char buf[128], *s;
  FILE *f;
  snprintf(buf, sizeof buf, "/sys/class/rtc/%s/device/power/wakeup", devname);
  f = fopen(buf, "r");
  if (!f) {
    perror(buf);
    return 0;
  }
  fgets(buf, sizeof buf, f);
  fclose(f);
  s = strchr(buf, '\n');
  if (!s)
    return 0;
  *s = 0;
  return strcmp(buf, "enabled") == 0;
}


x86 assembly (clang, -O0):
<may_wakeup>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x80,%esi
lea    0xe6a(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0xa0(%rbp)
cmpq   $0x0,-0xa0(%rbp)
jne    11db <may_wakeup+0x6b>
lea    -0x90(%rbp),%rdi
call   1090 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    125d <may_wakeup+0xed>
lea    -0x90(%rbp),%rdi
mov    -0xa0(%rbp),%rdx
mov    $0x80,%esi
call   1060 <fgets@plt>
mov    -0xa0(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x90(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    1231 <may_wakeup+0xc1>
movl   $0x0,-0x4(%rbp)
jmp    125d <may_wakeup+0xed>
mov    -0x98(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x90(%rbp),%rdi
lea    0xddf(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<may_wakeup>:
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%rcx
lea    0xe7c(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1050 <snprintf@plt>
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f7 <may_wakeup+0x87>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11ff <may_wakeup+0x8f>
movb   $0x0,(%rax)
lea    0xe46(%rip),%rsi
mov    %rsp,%rdi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    1201 <may_wakeup+0x91>
mov    %rsp,%rdi
call   1090 <perror@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [38 x i8] c"/sys/class/rtc/%s/device/power/wakeup\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"enabled\00"
define i32 @may_wakeup(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [128 x i8]
%5 = alloca i8*
%6 = alloca i32*
store i8* %0, i8** %3
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @snprintf(i8* %7, i32 128, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %1
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%16 = call i32 @perror(i8* %15)
store i32 0, i32* %2
br label %34
17: ; preds = %1
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%19 = load i32*, i32** %6
%20 = call i32 @fgets(i8* %18, i32 128, i32* %19)
%21 = load i32*, i32** %6
%22 = call i32 @fclose(i32* %21)
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%24 = call i8* @strchr(i8* %23, i8 signext 10)
store i8* %24, i8** %5
%25 = load i8*, i8** %5
%26 = icmp ne i8* %25, null
br i1 %26, label %28, label %27
27: ; preds = %17
store i32 0, i32* %2
br label %34
28: ; preds = %17
%29 = load i8*, i8** %5
store i8 0, i8* %29
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
%33 = zext i1 %32 to i32
store i32 %33, i32* %2
br label %34
34: ; preds = %28, %27, %14
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [38 x i8] c"/sys/class/rtc/%s/device/power/wakeup\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"enabled\00"
define i32 @may_wakeup(i8* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = call i32 @snprintf(i8* %3, i32 128, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @perror(i8* %3)
br label %18
9: ; preds = %1
%10 = call i32 @fgets(i8* %3, i32 128, i32* %5)
%11 = call i32 @fclose(i32* %5)
%12 = call i8* @strchr(i8* %3, i8 signext 10)
%13 = icmp eq i8* %12, null
br i1 %13, label %18, label %14
14: ; preds = %9
store i8 0, i8* %12
%15 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %9, %14, %7
%19 = phi i32 [ %17, %14 ], [ 0, %7 ], [ 0, %9 ]
ret i32 %19
}