#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*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int dm_cycle_change_inotify(int status) {
  FILE *p;
  char inotify_path[64];
  memset(inotify_path, 0, 64);
  if (status == 0x01)
    sprintf(inotify_path, "%s/%s", "/tmp/notify", "power");
  else if (status == 0x02)
    sprintf(inotify_path, "%s/%s", "/tmp/notify", "disk");
  else
    return -1;
  if (access(inotify_path, F_OK) == 0) {
    remove(inotify_path);
  } else {
    p = fopen(inotify_path, "w");
    fclose(p);
  }
  return 0;
}


x86 assembly (clang, -O0):
<dm_cycle_change_inotify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11a8 <dm_cycle_change_inotify+0x48>
lea    -0x50(%rbp),%rdi
lea    0xe70(%rip),%rsi
lea    0xe6f(%rip),%rdx
lea    0xe74(%rip),%rcx
call   1080 <sprintf@plt>
jmp    11e6 <dm_cycle_change_inotify+0x86>
cmpl   $0x2,-0x8(%rbp)
jne    11d5 <dm_cycle_change_inotify+0x75>
lea    -0x50(%rbp),%rdi
lea    0xe43(%rip),%rsi
lea    0xe42(%rip),%rdx
lea    0xe4d(%rip),%rcx
call   1080 <sprintf@plt>
jmp    11e1 <dm_cycle_change_inotify+0x81>
movl   $0xffffffff,-0x4(%rbp)
jmp    1234 <dm_cycle_change_inotify+0xd4>
jmp    11e6 <dm_cycle_change_inotify+0x86>
lea    -0x50(%rbp),%rdi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
jne    1210 <dm_cycle_change_inotify+0xb0>
lea    -0x50(%rbp),%rdi
call   1030 <remove@plt>
jmp    122d <dm_cycle_change_inotify+0xcd>
lea    -0x50(%rbp),%rdi
lea    0xe02(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dm_cycle_change_inotify>:
push   %rbx
sub    $0x40,%rsp
mov    %edi,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
cmp    $0x1,%ebx
je     118e <dm_cycle_change_inotify+0x2e>
mov    $0xffffffff,%eax
cmp    $0x2,%ebx
jne    11e7 <dm_cycle_change_inotify+0x87>
lea    0xe8c(%rip),%rcx
jmp    1195 <dm_cycle_change_inotify+0x35>
lea    0xe7d(%rip),%rcx
lea    0xe64(%rip),%rsi
lea    0xe63(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1080 <sprintf@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <access@plt>
test   %rax,%rax
je     11dd <dm_cycle_change_inotify+0x7d>
lea    0xe52(%rip),%rsi
mov    %rsp,%rdi
call   1070 <fopen@plt>
mov    %rax,%rdi
call   1040 <fclose@plt>
jmp    11e5 <dm_cycle_change_inotify+0x85>
mov    %rsp,%rdi
call   1030 <remove@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [12 x i8] c"/tmp/notify\00"
@.str.2 = [6 x i8] c"power\00"
@.str.3 = [5 x i8] c"disk\00"
@F_OK = global i32 0
@.str.4 = [2 x i8] c"w\00"
define i32 @dm_cycle_change_inotify(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [64 x i8]
store i32 %0, i32* %3
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 64)
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%12 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %21
13: ; preds = %1
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%18 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %20
19: ; preds = %13
store i32 -1, i32* %2
br label %35
20: ; preds = %16
br label %21
21: ; preds = %20, %10
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%23 = load i32, i32* @F_OK
%24 = call i64 @access(i8* %22, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%28 = call i32 @remove(i8* %27)
br label %34
29: ; preds = %21
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %31, i32** %4
%32 = load i32*, i32** %4
%33 = call i32 @fclose(i32* %32)
br label %34
34: ; preds = %29, %26
store i32 0, i32* %2
br label %35
35: ; preds = %34, %19
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [12 x i8] c"/tmp/notify\00"
@.str.2 = [6 x i8] c"power\00"
@.str.3 = [5 x i8] c"disk\00"
@F_OK = global i32 0
@.str.4 = [2 x i8] c"w\00"
define i32 @dm_cycle_change_inotify(i32 %0) {
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 64)
switch i32 %0, label %17 [
i32 1, label %6
i32 2, label %5
]
5: ; preds = %1
br label %6
6: ; preds = %1, %5
%7 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %5 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %1 ]
%8 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @F_OK
%10 = call i64 @access(i8* %3, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = call i32 @remove(i8* %3)
br label %17
14: ; preds = %6
%15 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @fclose(i32* %15)
br label %17
17: ; preds = %12, %14, %1
%18 = phi i32 [ -1, %1 ], [ 0, %14 ], [ 0, %12 ]
ret i32 %18
}