#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int);
int strlen(char *);
int enable_timer(unsigned int on_ms, unsigned int off_ms) {
  FILE *f = fopen("/sys/class/leds/"
                  "power"
                  "/trigger",
                  "w");
  if (!f)
    return -1;
  fwrite("timer", sizeof "timer", 1, f);
  fclose(f);
  char buf[16];
  sprintf(buf, "%u", on_ms);
  size_t len = strlen(buf) + 1;
  f = fopen("/sys/class/leds/"
            "power"
            "/delay_on",
            "w");
  if (!f)
    return -1;
  fwrite(buf, len, 1, f);
  fclose(f);
  sprintf(buf, "%u", off_ms);
  len = strlen(buf) + 1;
  f = fopen("/sys/class/leds/"
            "power"
            "/delay_off",
            "w");
  if (!f)
    return -1;
  fwrite(buf, len, 1, f);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<enable_timer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe9b(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118c <enable_timer+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    129a <enable_timer+0x14a>
mov    -0x18(%rbp),%rcx
lea    0xe89(%rip),%rdi
mov    $0x6,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe69(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x38(%rbp)
lea    0xe4e(%rip),%rdi
lea    0xe3c(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1202 <enable_timer+0xb2>
movl   $0xffffffff,-0x4(%rbp)
jmp    129a <enable_timer+0x14a>
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xdf7(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x38(%rbp)
lea    0xdfb(%rip),%rdi
lea    0xdca(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1274 <enable_timer+0x124>
movl   $0xffffffff,-0x4(%rbp)
jmp    129a <enable_timer+0x14a>
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enable_timer>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xe9a(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     125f <enable_timer+0x10f>
mov    %rax,%rbx
lea    0xe9b(%rip),%rdi
mov    $0x6,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe80(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %ebp,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0xe65(%rip),%rdi
lea    0xe53(%rip),%rsi
call   1050 <fopen@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
je     1265 <enable_timer+0x115>
mov    %rax,%rbx
add    $0x1,%ebp
movslq %ebp,%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe1c(%rip),%rsi
mov    %rbp,%rdi
mov    %r14d,%edx
call   1060 <sprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
lea    0xe21(%rip),%rdi
lea    0xdf0(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1265 <enable_timer+0x115>
mov    %rax,%rbx
add    $0x1,%r14d
movslq %r14d,%rsi
mov    %rsp,%rdi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %r15d,%r15d
jmp    1265 <enable_timer+0x115>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"/sys/class/leds/power/trigger\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"timer\00"
@.str.3 = [3 x i8] c"%u\00"
@.str.4 = [31 x i8] c"/sys/class/leds/power/delay_on\00"
@.str.5 = [32 x i8] c"/sys/class/leds/power/delay_off\00"
define i32 @enable_timer(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca [16 x i8]
%8 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp ne i32* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 -1, i32* %3
br label %54
13: ; preds = %2
%14 = load i32*, i32** %6
%15 = call i32 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 6, i32 1, i32* %14)
%16 = load i32*, i32** %6
%17 = call i32 @fclose(i32* %16)
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%19 = load i32, i32* %4
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
store i64 %24, i64* %8
%25 = call i32* @fopen(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %6
%26 = load i32*, i32** %6
%27 = icmp ne i32* %26, null
br i1 %27, label %29, label %28
28: ; preds = %13
store i32 -1, i32* %3
br label %54
29: ; preds = %13
%30 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%31 = load i64, i64* %8
%32 = load i32*, i32** %6
%33 = call i32 @fwrite(i8* %30, i64 %31, i32 1, i32* %32)
%34 = load i32*, i32** %6
%35 = call i32 @fclose(i32* %34)
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%37 = load i32, i32* %5
%38 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = add nsw i32 %40, 1
%42 = sext i32 %41 to i64
store i64 %42, i64* %8
%43 = call i32* @fopen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %43, i32** %6
%44 = load i32*, i32** %6
%45 = icmp ne i32* %44, null
br i1 %45, label %47, label %46
46: ; preds = %29
store i32 -1, i32* %3
br label %54
47: ; preds = %29
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%49 = load i64, i64* %8
%50 = load i32*, i32** %6
%51 = call i32 @fwrite(i8* %48, i64 %49, i32 1, i32* %50)
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
store i32 0, i32* %3
br label %54
54: ; preds = %47, %46, %28, %12
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [30 x i8] c"/sys/class/leds/power/trigger\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"timer\00"
@.str.3 = [3 x i8] c"%u\00"
@.str.4 = [31 x i8] c"/sys/class/leds/power/delay_on\00"
@.str.5 = [32 x i8] c"/sys/class/leds/power/delay_off\00"
define i32 @enable_timer(i32 %0, i32 %1) {
%3 = alloca [16 x i8]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %30, label %6
6: ; preds = %2
%7 = tail call i32 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 6, i32 1, i32* %4)
%8 = tail call i32 @fclose(i32* %4)
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%10 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %0)
%11 = call i32 @strlen(i8* %9)
%12 = call i32* @fopen(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %28, label %14
14: ; preds = %6
%15 = add nsw i32 %11, 1
%16 = sext i32 %15 to i64
%17 = call i32 @fwrite(i8* %9, i64 %16, i32 1, i32* %12)
%18 = call i32 @fclose(i32* %12)
%19 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %1)
%20 = call i32 @strlen(i8* %9)
%21 = call i32* @fopen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %28, label %23
23: ; preds = %14
%24 = add nsw i32 %20, 1
%25 = sext i32 %24 to i64
%26 = call i32 @fwrite(i8* %9, i64 %25, i32 1, i32* %21)
%27 = call i32 @fclose(i32* %21)
br label %28
28: ; preds = %14, %6, %23
%29 = phi i32 [ 0, %23 ], [ -1, %6 ], [ -1, %14 ]
br label %30
30: ; preds = %2, %28
%31 = phi i32 [ %29, %28 ], [ -1, %2 ]
ret i32 %31
}