#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 */
struct timespec {
  int tv_nsec;
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ err(int, char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int main(void) {
  FILE *f;
  struct timespec req = {.tv_sec = 0, .tv_nsec = 250 * 1000000};
  f = fopen("/sys/class/leds/tpacpi::thinklight/brightness", "w");
  if (f == NULL)
    err(1, "fopen(\"%s\")", "/sys/class/leds/tpacpi::thinklight/brightness");
  fprintf(f, "%u\n", 255);
  fflush(f);
  nanosleep(&req, NULL);
  fprintf(f, "%u\n", 0);
  fclose(f);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe87(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b4 <main+0x54>
mov    $0x1,%edi
lea    0xe90(%rip),%rsi
lea    0xe59(%rip),%rdx
call   1060 <err@plt>
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
mov    $0xff,%edx
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <fflush@plt>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <nanosleep@plt>
mov    -0x10(%rbp),%rdi
lea    0xe5a(%rip),%rsi
xor    %edx,%edx
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
movq   $0xee6b280,(%rsp)
0e
lea    0xe8d(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    119f <main+0x3f>
lea    0xea2(%rip),%rsi
lea    0xe6b(%rip),%rdx
mov    $0x1,%edi
call   1060 <err@plt>
lea    0xe96(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xff,%edx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@__const.main.req = %struct.timespec { i32 250000000, i32 0 }
@.str = [46 x i8] c"/sys/class/leds/tpacpi::thinklight/brightness\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [12 x i8] c"fopen(\22%s\22)\00"
@.str.3 = [4 x i8] c"%u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.timespec
store i32 0, i32* %1
%4 = bitcast %struct.timespec* %3 to i8*
%5 = call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = load i32*, i32** %2
%12 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 255)
%13 = load i32*, i32** %2
%14 = call i32 @fflush(i32* %13)
%15 = call i32 @nanosleep(%struct.timespec* %3, i32* null)
%16 = load i32*, i32** %2
%17 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 0)
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@.str = [46 x i8] c"/sys/class/leds/tpacpi::thinklight/brightness\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [12 x i8] c"fopen(\22%s\22)\00"
@.str.3 = [4 x i8] c"%u\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
store i64 250000000, i64* %1
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = bitcast i64* %1 to %struct.timespec*
%9 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 255)
%10 = tail call i32 @fflush(i32* %3)
%11 = call i32 @nanosleep(%struct.timespec* %8, i32* null)
%12 = call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 0)
%13 = call i32 @fclose(i32* %3)
ret i32 0
}