#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
struct input_event {
  int code;
  int value;
  int /*<<< orphan*/ type;
  TYPE_1__ time;
};
typedef int /*<<< orphan*/ ev;

/* Variables and functions */
int /*<<< orphan*/ EV_KEY;
int /*<<< orphan*/ EV_LED;
int /*<<< orphan*/ EV_SYN;
int KEY_ESC;
int SYN_REPORT;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int, struct input_event *, int);
void flash_led(int fd) {
  static int state = 0;
  struct input_event ev[4];
  int i;
  state ^= 1;
  for (i = 0; i < 1; i++) {
    ev[i].time.tv_sec = 0;
    ev[i].time.tv_usec = 0;
    ev[i].type = EV_LED;
    ev[i].code = i;
    ev[i].value = state;
  }
  ev[i].type = EV_KEY;
  ev[i].code = KEY_ESC;
  ev[i].value = state;
  i++;
  ev[i].type = EV_SYN;
  ev[i].code = SYN_REPORT;
  ev[i].value = 0;
  i++;
  int sz = write(fd, ev, sizeof(ev[0]) * i);
  if (sz < 0) {
    fprintf(stderr, "Error %s in write\n", strerror(errno));
  }
}


x86 assembly (clang, -O0):
<flash_led>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2ef8(%rip),%eax
xor    $0x1,%eax
mov    %eax,0x2eef(%rip)
movl   $0x0,-0x94(%rbp)
cmpl   $0x1,-0x94(%rbp)
jge    120e <flash_led+0xde>
movslq -0x94(%rbp),%rcx
lea    -0x90(%rbp),%rax
shl    $0x5,%rcx
add    %rcx,%rax
movq   $0x0,0x18(%rax)
movslq -0x94(%rbp),%rcx
lea    -0x90(%rbp),%rax
shl    $0x5,%rcx
add    %rcx,%rax
movq   $0x0,0x10(%rax)
mov    0x2e33(%rip),%rax
mov    (%rax),%ecx
movslq -0x94(%rbp),%rdx
lea    -0x90(%rbp),%rax
shl    $0x5,%rdx
add    %rdx,%rax
mov    %ecx,0x8(%rax)
mov    -0x94(%rbp),%ecx
movslq -0x94(%rbp),%rdx
lea    -0x90(%rbp),%rax
shl    $0x5,%rdx
add    %rdx,%rax
mov    %ecx,(%rax)
mov    0x2e5a(%rip),%ecx
movslq -0x94(%rbp),%rdx
lea    -0x90(%rbp),%rax
shl    $0x5,%rdx
add    %rdx,%rax
mov    %ecx,0x4(%rax)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    1157 <flash_led+0x27>
mov    0x2dbb(%rip),%rax
mov    (%rax),%ecx
movslq -0x94(%rbp),%rdx
lea    -0x90(%rbp),%rax
shl    $0x5,%rdx
add    %rdx,%rax
mov    %ecx,0x8(%rax)
mov    0x2daa(%rip),%rax
mov    (%rax),%ecx
movslq -0x94(%rbp),%rdx
lea    -0x90(%rbp),%rax
shl    $0x5,%rdx
add    %rdx,%rax
mov    %ecx,(%rax)
mov    0x2de7(%rip),%ecx
movslq -0x94(%rbp),%rdx
lea    -0x90(%rbp),%rax
shl    $0x5,%rdx
add    %rdx,%rax
mov    %ecx,0x4(%rax)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
mov    0x2d6d(%rip),%rax
mov    (%rax),%ecx
movslq -0x94(%rbp),%rdx
lea    -0x90(%rbp),%rax
shl    $0x5,%rdx
add    %rdx,%rax
mov    %ecx,0x8(%rax)
mov    0x2d24(%rip),%rax
mov    (%rax),%ecx
movslq -0x94(%rbp),%rdx
lea    -0x90(%rbp),%rax
shl    $0x5,%rdx
add    %rdx,%rax
mov    %ecx,(%rax)
movslq -0x94(%rbp),%rcx
lea    -0x90(%rbp),%rax
shl    $0x5,%rcx
add    %rcx,%rax
movl   $0x0,0x4(%rax)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x90(%rbp),%rsi
movslq -0x94(%rbp),%rax
shl    $0x5,%rax
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x98(%rbp)
cmpl   $0x0,-0x98(%rbp)
jge    1349 <flash_led+0x219>
mov    0x2c9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x9c(%rbp),%edi
mov    %rax,%rdx
lea    0xcbc(%rip),%rsi
call   1040 <fprintf@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flash_led>:
push   %rbx
sub    $0x80,%rsp
mov    0x2efe(%rip),%eax
xor    $0x1,%eax
mov    %eax,0x2ef5(%rip)
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
mov    0x2e82(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x8(%rsp)
movl   $0x0,(%rsp)
mov    %eax,0x4(%rsp)
mov    0x2e62(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x28(%rsp)
mov    0x2e65(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x20(%rsp)
mov    %eax,0x24(%rsp)
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x48(%rsp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x40(%rsp)
movl   $0x0,0x44(%rsp)
mov    %rsp,%rsi
mov    $0x60,%edx
call   1030 <write@plt>
test   %eax,%eax
js     11c1 <flash_led+0x91>
add    $0x80,%rsp
pop    %rbx
ret
mov    0x2df0(%rip),%rax
mov    (%rax),%ebx
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe21(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
add    $0x80,%rsp
pop    %rbx
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
%struct.input_event = type { i32, i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64, i64 }
@flash_led.state = internal global i32 0
@EV_LED = global i32 0
@EV_KEY = global i32 0
@KEY_ESC = global i32 0
@EV_SYN = global i32 0
@SYN_REPORT = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"Error %s in write\0A\00"
@errno = global i32 0
define void @flash_led(i32 %0) {
%2 = alloca i32
%3 = alloca [4 x %struct.input_event]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* @flash_led.state
%7 = xor i32 %6, 1
store i32 %7, i32* @flash_led.state
store i32 0, i32* %4
br label %8
8: ; preds = %37, %1
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %40
11: ; preds = %8
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %3, i64 0, i64 %13
%15 = getelementptr inbounds %struct.input_event, %struct.input_event* %14, i32 0, i32 3
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 1
store i64 0, i64* %16
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %3, i64 0, i64 %18
%20 = getelementptr inbounds %struct.input_event, %struct.input_event* %19, i32 0, i32 3
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i64 0, i64* %21
%22 = load i32, i32* @EV_LED
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %3, i64 0, i64 %24
%26 = getelementptr inbounds %struct.input_event, %struct.input_event* %25, i32 0, i32 2
store i32 %22, i32* %26
%27 = load i32, i32* %4
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %3, i64 0, i64 %29
%31 = getelementptr inbounds %struct.input_event, %struct.input_event* %30, i32 0, i32 0
store i32 %27, i32* %31
%32 = load i32, i32* @flash_led.state
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %3, i64 0, i64 %34
%36 = getelementptr inbounds %struct.input_event, %struct.input_event* %35, i32 0, i32 1
store i32 %32, i32* %36
br label %37
37: ; preds = %11
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %8
40: ; preds = %8
%41 = load i32, i32* @EV_KEY
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %3, i64 0, i64 %43
%45 = getelementptr inbounds %struct.input_event, %struct.input_event* %44, i32 0, i32 2
store i32 %41, i32* %45
%46 = load i32, i32* @KEY_ESC
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %3, i64 0, i64 %48
%50 = getelementptr inbounds %struct.input_event, %struct.input_event* %49, i32 0, i32 0
store i32 %46, i32* %50
%51 = load i32, i32* @flash_led.state
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %3, i64 0, i64 %53
%55 = getelementptr inbounds %struct.input_event, %struct.input_event* %54, i32 0, i32 1
store i32 %51, i32* %55
%56 = load i32, i32* %4
%57 = add nsw i32 %56, 1
store i32 %57, i32* %4
%58 = load i32, i32* @EV_SYN
%59 = load i32, i32* %4
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %3, i64 0, i64 %60
%62 = getelementptr inbounds %struct.input_event, %struct.input_event* %61, i32 0, i32 2
store i32 %58, i32* %62
%63 = load i32, i32* @SYN_REPORT
%64 = load i32, i32* %4
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %3, i64 0, i64 %65
%67 = getelementptr inbounds %struct.input_event, %struct.input_event* %66, i32 0, i32 0
store i32 %63, i32* %67
%68 = load i32, i32* %4
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %3, i64 0, i64 %69
%71 = getelementptr inbounds %struct.input_event, %struct.input_event* %70, i32 0, i32 1
store i32 0, i32* %71
%72 = load i32, i32* %4
%73 = add nsw i32 %72, 1
store i32 %73, i32* %4
%74 = load i32, i32* %2
%75 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %3, i64 0, i64 0
%76 = load i32, i32* %4
%77 = sext i32 %76 to i64
%78 = mul i64 32, %77
%79 = trunc i64 %78 to i32
%80 = call i32 @write(i32 %74, %struct.input_event* %75, i32 %79)
store i32 %80, i32* %5
%81 = load i32, i32* %5
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %88
83: ; preds = %40
%84 = load i32, i32* @stderr
%85 = load i32, i32* @errno
%86 = call i8* @strerror(i32 %85)
%87 = call i32 @fprintf(i32 %84, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %86)
br label %88
88: ; preds = %83, %40
ret void
}

LLVM IR (-O2):
%struct.input_event = type { i32, i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64, i64 }
@flash_led.state = internal unnamed_addr global i32 0
@EV_LED = global i32 0
@EV_KEY = global i32 0
@KEY_ESC = global i32 0
@EV_SYN = global i32 0
@SYN_REPORT = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"Error %s in write\0A\00"
@errno = global i32 0
define void @flash_led(i32 %0) {
%2 = alloca [4 x %struct.input_event]
%3 = bitcast [4 x %struct.input_event]* %2 to i8*
%4 = load i32, i32* @flash_led.state
%5 = xor i32 %4, 1
store i32 %5, i32* @flash_led.state
%6 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %2, i64 0, i64 0, i32 3, i32 0
%7 = bitcast i64* %6 to i8*
%8 = load i32, i32* @EV_LED
%9 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %2, i64 0, i64 0, i32 2
store i32 %8, i32* %9
%10 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %2, i64 0, i64 0, i32 0
store i32 0, i32* %10
%11 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %2, i64 0, i64 0, i32 1
store i32 %5, i32* %11
%12 = load i32, i32* @EV_KEY
%13 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %2, i64 0, i64 1, i32 2
store i32 %12, i32* %13
%14 = load i32, i32* @KEY_ESC
%15 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %2, i64 0, i64 1, i32 0
store i32 %14, i32* %15
%16 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %2, i64 0, i64 1, i32 1
store i32 %5, i32* %16
%17 = load i32, i32* @EV_SYN
%18 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %2, i64 0, i64 2, i32 2
store i32 %17, i32* %18
%19 = load i32, i32* @SYN_REPORT
%20 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %2, i64 0, i64 2, i32 0
store i32 %19, i32* %20
%21 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %2, i64 0, i64 2, i32 1
store i32 0, i32* %21
%22 = getelementptr inbounds [4 x %struct.input_event], [4 x %struct.input_event]* %2, i64 0, i64 0
%23 = call i32 @write(i32 %0, %struct.input_event* %22, i32 96)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %1
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = tail call i8* @strerror(i32 %27)
%29 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %25, %1
ret void
}