#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 */
scalar_t__ calloc(int, int);
int count_lights(int *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ get_range(int /*<<< orphan*/ *, int *, int *, int *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ set_all_lights(int *, int, int, int, int, int);
int strcmp(char *, char *);
int /*<<< orphan*/ toggle_all_lights(int *, int, int, int, int);
int main(void) {
  FILE *fp;
  char buf[256];
  int *lights;
  lights = (int *)calloc(1000 * 1000, sizeof(int));
  fp = fopen("input.txt", "r");
  while (fscanf(fp, "%s", buf) && !feof(fp)) {
    if (!strcmp(buf, "toggle")) {
      int sx, sy, ex, ey;
      get_range(fp, &sx, &sy, &ex, &ey);
      toggle_all_lights(lights, sx, sy, ex, ey);
    } else if (!strcmp(buf, "turn")) {
      fscanf(fp, "%s", buf);
      int on = strcmp(buf, "off");
      int sx, sy, ex, ey;
      get_range(fp, &sx, &sy, &ex, &ey);
      set_all_lights(lights, sx, sy, ex, ey, on);
    } else {
      printf("Unknown action '%s'\n", buf);
      return 1;
    }
  }
  printf("Lights turned on: %d\n", count_lights(lights));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xf4240,%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,-0x118(%rbp)
lea    0xe31(%rip),%rdi
lea    0xe34(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x110(%rbp),%rdx
lea    0xe1b(%rip),%rsi
call   1060 <fscanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x13d(%rbp)
je     1222 <main+0x82>
mov    -0x10(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x13d(%rbp)
mov    -0x13d(%rbp),%al
test   $0x1,%al
jne    1235 <main+0x95>
jmp    136d <main+0x1cd>
lea    -0x110(%rbp),%rdi
lea    0xdcc(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    12a0 <main+0x100>
mov    -0x10(%rbp),%rdi
lea    -0x11c(%rbp),%rsi
lea    -0x120(%rbp),%rdx
lea    -0x124(%rbp),%rcx
lea    -0x128(%rbp),%r8
call   1030 <get_range@plt>
mov    -0x118(%rbp),%rdi
mov    -0x11c(%rbp),%esi
mov    -0x120(%rbp),%edx
mov    -0x124(%rbp),%ecx
mov    -0x128(%rbp),%r8d
call   1040 <toggle_all_lights@plt>
jmp    1368 <main+0x1c8>
lea    -0x110(%rbp),%rdi
lea    0xd68(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1342 <main+0x1a2>
mov    -0x10(%rbp),%rdi
lea    -0x110(%rbp),%rdx
lea    0xd3e(%rip),%rsi
call   1060 <fscanf@plt>
lea    -0x110(%rbp),%rdi
lea    0xd3a(%rip),%rsi
call   1080 <strcmp@plt>
mov    %eax,-0x12c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x130(%rbp),%rsi
lea    -0x134(%rbp),%rdx
lea    -0x138(%rbp),%rcx
lea    -0x13c(%rbp),%r8
call   1030 <get_range@plt>
mov    -0x118(%rbp),%rdi
mov    -0x130(%rbp),%esi
mov    -0x134(%rbp),%edx
mov    -0x138(%rbp),%ecx
mov    -0x13c(%rbp),%r8d
mov    -0x12c(%rbp),%r9d
call   10b0 <set_all_lights@plt>
jmp    1363 <main+0x1c3>
lea    -0x110(%rbp),%rsi
lea    0xccf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1389 <main+0x1e9>
jmp    1368 <main+0x1c8>
jmp    11df <main+0x3f>
mov    -0x118(%rbp),%rdi
call   10a0 <count_lights@plt>
mov    %eax,%esi
lea    0xcb2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    $0xf4240,%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,%r14
lea    0xe36(%rip),%rdi
lea    0xe39(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
lea    0xe2c(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
test   %rax,%rax
je     12f1 <main+0x151>
lea    0xc(%rsp),%rbp
lea    0xe0a(%rip),%r15
lea    0x10(%rsp),%r12
jmp    1257 <main+0xb7>
nopl   0x0(%rax)
mov    %rbx,%rdi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %rsp,%rcx
mov    %rbp,%r8
call   1030 <get_range@plt>
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
mov    (%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    %r14,%rdi
call   1040 <toggle_all_lights@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <fscanf@plt>
test   %rax,%rax
je     12f1 <main+0x151>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    12f1 <main+0x151>
mov    0x10(%rsp),%eax
mov    $0x67676f74,%ecx
xor    %ecx,%eax
mov    0x13(%rsp),%ecx
mov    $0x656c67,%edx
xor    %edx,%ecx
or     %eax,%ecx
je     1210 <main+0x70>
mov    0x10(%rsp),%eax
mov    $0x6e727574,%ecx
xor    %ecx,%eax
movzbl 0x14(%rsp),%ecx
or     %eax,%ecx
jne    131f <main+0x17f>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <fscanf@plt>
mov    %r12,%rdi
lea    0xd6a(%rip),%rsi
call   1080 <strcmp@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %rsp,%rcx
mov    %rbp,%r8
call   1030 <get_range@plt>
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
mov    (%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    %r14,%rdi
mov    %r13d,%r9d
call   10b0 <set_all_lights@plt>
jmp    1240 <main+0xa0>
mov    %r14,%rdi
call   10a0 <count_lights@plt>
lea    0xd34(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcf9(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
jmp    130b <main+0x16b>

LLVM IR (-O0):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [7 x i8] c"toggle\00"
@.str.4 = [5 x i8] c"turn\00"
@.str.5 = [4 x i8] c"off\00"
@.str.6 = [21 x i8] c"Unknown action '%s'\0A\00"
@.str.7 = [22 x i8] c"Lights turned on: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [256 x i8]
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %1
%14 = call i64 @calloc(i32 1000000, i32 4)
%15 = inttoptr i64 %14 to i32*
store i32* %15, i32** %4
%16 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %2
br label %17
17: ; preds = %65, %0
%18 = load i32*, i32** %2
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%20 = call i64 @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i32*, i32** %2
%24 = call i32 @feof(i32* %23)
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
br label %27
27: ; preds = %22, %17
%28 = phi i1 [ false, %17 ], [ %26, %22 ]
br i1 %28, label %29, label %66
29: ; preds = %27
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%31 = call i32 @strcmp(i8* %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp ne i32 %31, 0
br i1 %32, label %42, label %33
33: ; preds = %29
%34 = load i32*, i32** %2
%35 = call i32 @get_range(i32* %34, i32* %5, i32* %6, i32* %7, i32* %8)
%36 = load i32*, i32** %4
%37 = load i32, i32* %5
%38 = load i32, i32* %6
%39 = load i32, i32* %7
%40 = load i32, i32* %8
%41 = call i32 @toggle_all_lights(i32* %36, i32 %37, i32 %38, i32 %39, i32 %40)
br label %65
42: ; preds = %29
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%44 = call i32 @strcmp(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%45 = icmp ne i32 %44, 0
br i1 %45, label %61, label %46
46: ; preds = %42
%47 = load i32*, i32** %2
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%49 = call i64 @fscanf(i32* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %48)
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%51 = call i32 @strcmp(i8* %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
store i32 %51, i32* %9
%52 = load i32*, i32** %2
%53 = call i32 @get_range(i32* %52, i32* %10, i32* %11, i32* %12, i32* %13)
%54 = load i32*, i32** %4
%55 = load i32, i32* %10
%56 = load i32, i32* %11
%57 = load i32, i32* %12
%58 = load i32, i32* %13
%59 = load i32, i32* %9
%60 = call i32 @set_all_lights(i32* %54, i32 %55, i32 %56, i32 %57, i32 %58, i32 %59)
br label %64
61: ; preds = %42
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %62)
store i32 1, i32* %1
br label %70
64: ; preds = %46
br label %65
65: ; preds = %64, %33
br label %17
66: ; preds = %27
%67 = load i32*, i32** %4
%68 = call i32 @count_lights(i32* %67)
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %68)
br label %70
70: ; preds = %66, %61
%71 = load i32, i32* %1
ret i32 %71
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [7 x i8] c"toggle\00"
@.str.4 = [5 x i8] c"turn\00"
@.str.5 = [4 x i8] c"off\00"
@.str.6 = [21 x i8] c"Unknown action '%s'\0A\00"
@.str.7 = [22 x i8] c"Lights turned on: %d\0A\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%11 = tail call i64 @calloc(i32 1000000, i32 4)
%12 = inttoptr i64 %11 to i32*
%13 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = call i64 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%15 = icmp eq i64 %14, 0
br i1 %15, label %55, label %16
16: ; preds = %0
%17 = bitcast i32* %6 to i8*
%18 = bitcast i32* %7 to i8*
%19 = bitcast i32* %8 to i8*
%20 = bitcast i32* %9 to i8*
%21 = bitcast i32* %2 to i8*
%22 = bitcast i32* %3 to i8*
%23 = bitcast i32* %4 to i8*
%24 = bitcast i32* %5 to i8*
br label %25
25: ; preds = %16, %52
%26 = call i32 @feof(i32* %13)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %55
28: ; preds = %25
%29 = call i32 @bcmp(i8* dereferenceable(7) %10, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 7)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = call i32 @get_range(i32* %13, i32* %2, i32* %3, i32* %4, i32* %5)
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = load i32, i32* %4
%36 = load i32, i32* %5
%37 = call i32 @toggle_all_lights(i32* %12, i32 %33, i32 %34, i32 %35, i32 %36)
br label %52
38: ; preds = %28
%39 = call i32 @bcmp(i8* dereferenceable(5) %10, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 5)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %50
41: ; preds = %38
%42 = call i64 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%43 = call i32 @strcmp(i8* %10, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%44 = call i32 @get_range(i32* %13, i32* %6, i32* %7, i32* %8, i32* %9)
%45 = load i32, i32* %6
%46 = load i32, i32* %7
%47 = load i32, i32* %8
%48 = load i32, i32* %9
%49 = call i32 @set_all_lights(i32* %12, i32 %45, i32 %46, i32 %47, i32 %48, i32 %43)
br label %52
50: ; preds = %38
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %10)
br label %58
52: ; preds = %41, %31
%53 = call i64 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %25
55: ; preds = %25, %52, %0
%56 = call i32 @count_lights(i32* %12)
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %55, %50
%59 = phi i32 [ 1, %50 ], [ 0, %55 ]
ret i32 %59
}