#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 */

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ init(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int /*<<< orphan*/ stdout;
int sum(int, int, int, int);
int /*<<< orphan*/ update(int, int, int);
int main() {
  int cmd, a1, a2, a3, a4;
  do {
    scanf("%d", &cmd);
    switch (cmd) {
    case 0:
      scanf("%d", &a1);
      init(a1);
      break;
    case 1:
      scanf("%d %d %d", &a1, &a2, &a3);
      update(a3, a1, a2);
      break;
    case 2:
      scanf("%d %d %d %d", &a1, &a2, &a3, &a4);
      printf("%d\n", sum(a1, a2, a3, a4));
      fflush(stdout);
      break;
    }
  } while (cmd != 3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe93(%rip),%rdi
xor    %eax,%eax
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     11b6 <main+0x56>
jmp    1194 <main+0x34>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
je     11d5 <main+0x75>
jmp    11a5 <main+0x45>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     1202 <main+0xa2>
jmp    124d <main+0xed>
lea    0xe4c(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0xc(%rbp),%edi
call   1060 <init@plt>
jmp    124d <main+0xed>
lea    0xe27(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <update@plt>
jmp    124d <main+0xed>
lea    0xdf7(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
lea    -0x18(%rbp),%r8
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1050 <sum@plt>
mov    %eax,%esi
lea    0xdd2(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
jmp    1252 <main+0xf2>
cmpl   $0x3,-0x8(%rbp)
jne    116f <main+0xf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe94(%rip),%rbx
lea    0x10(%rsp),%r14
lea    0x4(%rsp),%r12
lea    0xc(%rsp),%r13
lea    0x8(%rsp),%rbp
lea    0xe73(%rip),%r15
jmp    11d1 <main+0x71>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x8(%rsp),%edi
mov    0x4(%rsp),%esi
mov    0xc(%rsp),%edx
call   1030 <update@plt>
mov    0x10(%rsp),%eax
cmp    $0x3,%eax
je     1262 <main+0x102>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x10(%rsp),%eax
cmp    $0x2,%eax
je     1210 <main+0xb0>
cmp    $0x1,%eax
je     11a0 <main+0x40>
test   %eax,%eax
jne    11c8 <main+0x68>
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x4(%rsp),%edi
call   1060 <init@plt>
jmp    11c4 <main+0x64>
nopl   0x0(%rax,%rax,1)
lea    0xde9(%rip),%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
lea    0x14(%rsp),%r8
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x4(%rsp),%edi
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0x14(%rsp),%ecx
call   1050 <sum@plt>
lea    0xdc4(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
jmp    11c4 <main+0x64>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%d %d %d\00"
@.str.2 = [12 x i8] c"%d %d %d %d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
br label %7
7: ; preds = %31, %0
%8 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
switch i32 %9, label %30 [
i32 0, label %10
i32 1, label %14
i32 2, label %20
]
10: ; preds = %7
%11 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %3
%13 = call i32 @init(i32 %12)
br label %30
14: ; preds = %7
%15 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%16 = load i32, i32* %5
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = call i32 @update(i32 %16, i32 %17, i32 %18)
br label %30
20: ; preds = %7
%21 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %3, i32* %4, i32* %5, i32* %6)
%22 = load i32, i32* %3
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = call i32 @sum(i32 %22, i32 %23, i32 %24, i32 %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = load i32, i32* @stdout
%29 = call i32 @fflush(i32 %28)
br label %30
30: ; preds = %7, %20, %14, %10
br label %31
31: ; preds = %30
%32 = load i32, i32* %2
%33 = icmp ne i32 %32, 3
br i1 %33, label %7, label %34
34: ; preds = %31
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%d %d %d\00"
@.str.2 = [12 x i8] c"%d %d %d %d\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
br label %11
11: ; preds = %36, %0
%12 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%13 = load i32, i32* %1
switch i32 %13, label %36 [
i32 0, label %14
i32 1, label %18
i32 2, label %24
]
14: ; preds = %11
%15 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%16 = load i32, i32* %2
%17 = call i32 @init(i32 %16)
br label %34
18: ; preds = %11
%19 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%20 = load i32, i32* %4
%21 = load i32, i32* %2
%22 = load i32, i32* %3
%23 = call i32 @update(i32 %20, i32 %21, i32 %22)
br label %34
24: ; preds = %11
%25 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %2, i32* %3, i32* %4, i32* %5)
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = load i32, i32* %4
%29 = load i32, i32* %5
%30 = call i32 @sum(i32 %26, i32 %27, i32 %28, i32 %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = load i32, i32* @stdout
%33 = call i32 @fflush(i32 %32)
br label %34
34: ; preds = %24, %18, %14
%35 = load i32, i32* %1
br label %36
36: ; preds = %34, %11
%37 = phi i32 [ %35, %34 ], [ %13, %11 ]
%38 = icmp eq i32 %37, 3
br i1 %38, label %39, label %11
39: ; preds = %36
ret i32 0
}