#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*/ uint64_t;
typedef scalar_t__ uint32_t;

/* Variables and functions */
int EXIT_SUCCESS;
int atoi(char *);
int /*<<< orphan*/ convert_nth_position(scalar_t__ *, int);
int /*<<< orphan*/ free(char *);
scalar_t__ nth_position(scalar_t__, int);
int /*<<< orphan*/ printf(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ read_line(char **, size_t *);
int /*<<< orphan*/ sscanf(char *, char *, scalar_t__ *);
scalar_t__ strcmp(char *, char *);
char *strtok(char *, char *);
int main() {
  char *input = NULL;
  size_t size = 0;
  read_line(&input, &size);
  uint32_t floor;
  uint64_t points = 0;
  int ligthsOnCount = 0;
  while (strcmp(input, "Stop, God damn it") != 0) {
    sscanf(input, "%u", &floor);
    read_line(&input, &size);
    char *token = strtok(input, " ");
    while (token) {
      int currentApartment = atoi(token);
      convert_nth_position(&floor, currentApartment);
      token = strtok(NULL, " ");
    }
    points += floor;
    int i;
    for (i = 0; i < 32; i++) {
      if (nth_position(floor, i)) {
        ligthsOnCount++;
      }
    }
    read_line(&input, &size);
  }
  printf("Bohemcho left %d lights on and his score is %llu", ligthsOnCount,
         points);
  free(input);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <read_line@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     12b8 <main+0x128>
mov    -0x10(%rbp),%rdi
lea    0xe23(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <sscanf@plt>
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <read_line@plt>
mov    -0x10(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1255 <main+0xc5>
mov    -0x30(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    -0x20(%rbp),%rdi
call   1040 <convert_nth_position@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdce(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    1219 <main+0x89>
mov    -0x20(%rbp),%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x20,-0x38(%rbp)
jge    12a6 <main+0x116>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%esi
call   1090 <nth_position@plt>
cmp    $0x0,%rax
je     1293 <main+0x103>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1298 <main+0x108>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    126a <main+0xda>
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <read_line@plt>
jmp    11ca <main+0x3a>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xd52(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1080 <read_line@plt>
mov    0x8(%rsp),%rdi
lea    0xe35(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     12da <main+0x14a>
xor    %r12d,%r12d
lea    0x18(%rsp),%r15
lea    0x8(%rsp),%r13
lea    0x10(%rsp),%rbx
lea    0xe23(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,0x20(%rsp)
mov    0x8(%rsp),%rdi
lea    0xe01(%rip),%rsi
mov    %r15,%rdx
call   1070 <sscanf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1080 <read_line@plt>
mov    0x8(%rsp),%rdi
nopl   0x0(%rax)
mov    %r14,%rsi
call   10a0 <strtok@plt>
test   %rax,%rax
je     1260 <main+0xd0>
mov    %rax,%rdi
call   10b0 <atoi@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <convert_nth_position@plt>
xor    %edi,%edi
jmp    1230 <main+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x18(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
call   1090 <nth_position@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
mov    $0x1,%r13d
nopl   0x0(%rax)
mov    0x18(%rsp),%rdi
mov    %r13d,%esi
call   1090 <nth_position@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebp
add    $0x1,%r13d
cmp    $0x20,%r13d
jne    1280 <main+0xf0>
mov    0x20(%rsp),%rax
add    %r12d,%eax
mov    %rax,%r12
lea    0x8(%rsp),%r13
mov    %r13,%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1080 <read_line@plt>
mov    0x8(%rsp),%rdi
lea    0xd36(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1200 <main+0x70>
jmp    12df <main+0x14f>
xor    %ebp,%ebp
xor    %r12d,%r12d
lea    0xd31(%rip),%rdi
mov    %ebp,%esi
mov    %r12d,%edx
call   1050 <printf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x2cdf(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Stop, God damn it\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [49 x i8] c"Bohemcho left %d lights on and his score is %llu\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i8* null, i8** %2
store i64 0, i64* %3
%10 = call i32 @read_line(i8** %2, i64* %3)
store i32 0, i32* %5
store i32 0, i32* %6
br label %11
11: ; preds = %51, %0
%12 = load i8*, i8** %2
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %53
15: ; preds = %11
%16 = load i8*, i8** %2
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64* %4)
%18 = call i32 @read_line(i8** %2, i64* %3)
%19 = load i8*, i8** %2
%20 = call i8* @strtok(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %20, i8** %7
br label %21
21: ; preds = %24, %15
%22 = load i8*, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i8*, i8** %7
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = call i32 @convert_nth_position(i64* %4, i32 %27)
%29 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %29, i8** %7
br label %21
30: ; preds = %21
%31 = load i64, i64* %4
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = add nsw i64 %33, %31
%35 = trunc i64 %34 to i32
store i32 %35, i32* %5
store i32 0, i32* %9
br label %36
36: ; preds = %48, %30
%37 = load i32, i32* %9
%38 = icmp slt i32 %37, 32
br i1 %38, label %39, label %51
39: ; preds = %36
%40 = load i64, i64* %4
%41 = load i32, i32* %9
%42 = call i64 @nth_position(i64 %40, i32 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
br label %47
47: ; preds = %44, %39
br label %48
48: ; preds = %47
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
br label %36
51: ; preds = %36
%52 = call i32 @read_line(i8** %2, i64* %3)
br label %11
53: ; preds = %11
%54 = load i32, i32* %6
%55 = load i32, i32* %5
%56 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i32 %54, i32 %55)
%57 = load i8*, i8** %2
%58 = call i32 @free(i8* %57)
%59 = load i32, i32* @EXIT_SUCCESS
ret i32 %59
}

LLVM IR (-O2):
@.str = [18 x i8] c"Stop, God damn it\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [49 x i8] c"Bohemcho left %d lights on and his score is %llu\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i64
%4 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%5 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%6 = call i32 @read_line(i8** %1, i64* %2)
%7 = bitcast i64* %3 to i8*
%8 = load i8*, i8** %1
%9 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %49, label %11
11: ; preds = %0, %43
%12 = phi i32 [ %44, %43 ], [ 0, %0 ]
%13 = phi i32 [ %40, %43 ], [ 0, %0 ]
%14 = load i8*, i8** %1
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%16 = call i32 @read_line(i8** %1, i64* %2)
%17 = load i8*, i8** %1
%18 = call i8* @strtok(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %26, label %20
20: ; preds = %11, %20
%21 = phi i8* [ %24, %20 ], [ %18, %11 ]
%22 = call i32 @atoi(i8* %21)
%23 = call i32 @convert_nth_position(i64* %3, i32 %22)
%24 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %20
26: ; preds = %20, %11
%27 = load i64, i64* %3
%28 = trunc i64 %27 to i32
%29 = call i64 @nth_position(i64 %27, i32 0)
%30 = icmp ne i64 %29, 0
%31 = zext i1 %30 to i32
%32 = add nsw i32 %13, %31
br label %33
33: ; preds = %26, %33
%34 = phi i32 [ 1, %26 ], [ %41, %33 ]
%35 = phi i32 [ %32, %26 ], [ %40, %33 ]
%36 = load i64, i64* %3
%37 = call i64 @nth_position(i64 %36, i32 %34)
%38 = icmp ne i64 %37, 0
%39 = zext i1 %38 to i32
%40 = add nsw i32 %35, %39
%41 = add nuw nsw i32 %34, 1
%42 = icmp eq i32 %41, 32
br i1 %42, label %43, label %33
43: ; preds = %33
%44 = add i32 %12, %28
%45 = call i32 @read_line(i8** %1, i64* %2)
%46 = load i8*, i8** %1
%47 = call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %11
49: ; preds = %43, %0
%50 = phi i32 [ 0, %0 ], [ %40, %43 ]
%51 = phi i32 [ 0, %0 ], [ %44, %43 ]
%52 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i32 %50, i32 %51)
%53 = load i8*, i8** %1
%54 = call i32 @free(i8* %53)
%55 = load i32, i32* @EXIT_SUCCESS
ret i32 %55
}