#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 nwd(int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int input = 1;
  int ostatnieNWD[2];
  int sumaNWD = 0;
  int i = 0;
  while (input != 0) {
    scanf("%d", &input);
    if (input > 1) {
      ostatnieNWD[i % 2] = input;
      i++;
    }
    if (input == 1) {
      sumaNWD = sumaNWD + nwd(ostatnieNWD[0], ostatnieNWD[1]);
    }
    if (input == 0) {
      break;
    }
  }
  printf("%d", sumaNWD);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11cf <main+0x9f>
lea    0xe9b(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
jle    1196 <main+0x66>
mov    -0x8(%rbp),%ecx
mov    -0x18(%rbp),%eax
mov    $0x2,%esi
cltd
idiv   %esi
movslq %edx,%rax
mov    %ecx,-0x10(%rbp,%rax,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11bb <main+0x8b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <nwd@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11ca <main+0x9a>
jmp    11cf <main+0x9f>
jmp    1154 <main+0x24>
mov    -0x14(%rbp),%esi
lea    0xe27(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x1,0xc(%rsp)
xor    %ebx,%ebx
lea    0xeb5(%rip),%r14
lea    0xc(%rsp),%r15
xor    %ebp,%ebp
jmp    1181 <main+0x51>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%ecx
shr    $0x1f,%ecx
add    %ebp,%ecx
and    $0xfffffffe,%ecx
mov    %ebp,%edx
sub    %ecx,%edx
movslq %edx,%rcx
mov    %eax,0x10(%rsp,%rcx,4)
add    $0x1,%ebp
mov    $0x1,%eax
test   %eax,%eax
je     11af <main+0x7f>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
jge    1160 <main+0x30>
cmp    $0x1,%eax
jne    117d <main+0x4d>
mov    0x10(%rsp),%edi
mov    0x14(%rsp),%esi
call   1030 <nwd@plt>
add    %eax,%ebx
mov    0xc(%rsp),%eax
jmp    117d <main+0x4d>
lea    0xe4a(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%4 = bitcast [2 x i32]* %2 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
br label %7
7: ; preds = %0, %26
%8 = phi i32 [ 0, %0 ], [ %29, %26 ]
%9 = phi i32 [ 0, %0 ], [ %28, %26 ]
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %18
13: ; preds = %7
%14 = srem i32 %9, 2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 %15
store i32 %11, i32* %16
%17 = add nsw i32 %9, 1
br label %26
18: ; preds = %7
%19 = icmp eq i32 %11, 1
br i1 %19, label %20, label %26
20: ; preds = %18
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = call i32 @nwd(i32 %21, i32 %22)
%24 = add nsw i32 %23, %8
%25 = load i32, i32* %1
br label %26
26: ; preds = %13, %20, %18
%27 = phi i32 [ %11, %18 ], [ 1, %13 ], [ %25, %20 ]
%28 = phi i32 [ %9, %18 ], [ %17, %13 ], [ %9, %20 ]
%29 = phi i32 [ %8, %18 ], [ %8, %13 ], [ %24, %20 ]
%30 = icmp eq i32 %27, 0
br i1 %30, label %31, label %7
31: ; preds = %26
%32 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %29)
ret i32 0
}