#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*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  unsigned int n = 0;
  int array[100];
  int suma = 0;
  int prvaNula = 0;
  int drugaNula = 0;
  printf("Unesite duzinu niza: ");
  scanf("%d", &n);
  if (n <= 0 || n > 100) {
    perror("Array length out of range.");
    exit(1);
  }
  printf("Unos niza: \n");
  for (int i = 0; i < n; i++) {
    printf("Unesite %d. element: ", i + 1);
    scanf("%d", &array[i]);
    if (prvaNula == 1 && array[i] == 0) {
      drugaNula = 1;
    }
    if (array[i] == 0 && prvaNula == 0) {
      prvaNula = 1;
    }
    if (prvaNula == 1 && drugaNula == 0) {
      suma += array[i];
    }
  }
  printf("Ukupna suma brojeva izmedju prve i druge nule u nizu je: %d", suma);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x1a4(%rbp)
movl   $0x0,-0x1a8(%rbp)
movl   $0x0,-0x1ac(%rbp)
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf01(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jbe    11ab <main+0x6b>
cmpl   $0x64,-0x8(%rbp)
jbe    11c1 <main+0x81>
lea    0xe64(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1b0(%rbp)
mov    -0x1b0(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    12c7 <main+0x187>
mov    -0x1b0(%rbp),%esi
add    $0x1,%esi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x1b0(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x1,-0x1a8(%rbp)
jne    124e <main+0x10e>
movslq -0x1b0(%rbp),%rax
cmpl   $0x0,-0x1a0(%rbp,%rax,4)
jne    124e <main+0x10e>
movl   $0x1,-0x1ac(%rbp)
movslq -0x1b0(%rbp),%rax
cmpl   $0x0,-0x1a0(%rbp,%rax,4)
jne    127a <main+0x13a>
cmpl   $0x0,-0x1a8(%rbp)
jne    127a <main+0x13a>
movl   $0x1,-0x1a8(%rbp)
cmpl   $0x1,-0x1a8(%rbp)
jne    12ae <main+0x16e>
cmpl   $0x0,-0x1ac(%rbp)
jne    12ae <main+0x16e>
movslq -0x1b0(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
add    -0x1a4(%rbp),%eax
mov    %eax,-0x1a4(%rbp)
jmp    12b3 <main+0x173>
mov    -0x1b0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b0(%rbp)
jmp    11d9 <main+0x99>
mov    -0x1a4(%rbp),%esi
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1a8,%rsp
movl   $0x0,0xc(%rsp)
lea    0xe90(%rip),%rdi
xor    %r12d,%r12d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeff(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
add    $0xffffff9b,%eax
cmp    $0xffffff9b,%eax
jbe    1252 <main+0x102>
lea    0xedf(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
je     122d <main+0xdd>
lea    0x10(%rsp),%rbx
mov    $0x1,%r13d
xor    %ebp,%ebp
xor    %r14d,%r14d
xor    %r15d,%r15d
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
lea    0xe56(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe95(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %r15d,%eax
xor    $0x1,%eax
mov    (%rbx),%ecx
or     %ecx,%eax
cmove  %r13d,%r14d
mov    %ecx,%eax
or     %r15d,%eax
cmove  %r13d,%r15d
mov    %r15d,%eax
xor    $0x1,%eax
or     %r14d,%eax
mov    $0x0,%eax
cmovne %eax,%ecx
add    %ecx,%r12d
mov    0xc(%rsp),%eax
add    $0x4,%rbx
cmp    %rax,%rbp
jb     11d0 <main+0x80>
lea    0xe13(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdbd(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Unesite duzinu niza: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"Array length out of range.\00"
@.str.3 = [13 x i8] c"Unos niza: \0A\00"
@.str.4 = [22 x i8] c"Unesite %d. element: \00"
@.str.5 = [60 x i8] c"Ukupna suma brojeva izmedju prve i druge nule u nizu je: %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = icmp ule i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %0
%13 = load i32, i32* %2
%14 = icmp ugt i32 %13, 100
br i1 %14, label %15, label %18
15: ; preds = %12, %0
%16 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %12
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %7
br label %20
20: ; preds = %65, %18
%21 = load i32, i32* %7
%22 = load i32, i32* %2
%23 = icmp ult i32 %21, %22
br i1 %23, label %24, label %68
24: ; preds = %20
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %29
%31 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %30)
%32 = load i32, i32* %5
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %41
34: ; preds = %24
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %34
store i32 1, i32* %6
br label %41
41: ; preds = %40, %34, %24
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %41
%48 = load i32, i32* %5
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %47
store i32 1, i32* %5
br label %51
51: ; preds = %50, %47, %41
%52 = load i32, i32* %5
%53 = icmp eq i32 %52, 1
br i1 %53, label %54, label %64
54: ; preds = %51
%55 = load i32, i32* %6
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %64
57: ; preds = %54
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %59
%61 = load i32, i32* %60
%62 = load i32, i32* %4
%63 = add nsw i32 %62, %61
store i32 %63, i32* %4
br label %64
64: ; preds = %57, %54, %51
br label %65
65: ; preds = %64
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
br label %20
68: ; preds = %20
%69 = load i32, i32* %4
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), i32 %69)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Unesite duzinu niza: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"Array length out of range.\00"
@.str.4 = [22 x i8] c"Unesite %d. element: \00"
@.str.5 = [60 x i8] c"Ukupna suma brojeva izmedju prve i druge nule u nizu je: %d\00"
@str = [12 x i8] c"Unos niza: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = bitcast [100 x i32]* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = add i32 %7, -101
%9 = icmp ult i32 %8, -100
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%15 = load i32, i32* %1
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %20, %13
%18 = phi i32 [ 0, %13 ], [ %43, %20 ]
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), i32 %18)
ret i32 0
20: ; preds = %13, %20
%21 = phi i64 [ %25, %20 ], [ 0, %13 ]
%22 = phi i32 [ %34, %20 ], [ 0, %13 ]
%23 = phi i32 [ %38, %20 ], [ 0, %13 ]
%24 = phi i32 [ %43, %20 ], [ 0, %13 ]
%25 = add nuw nsw i64 %21, 1
%26 = trunc i64 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %21
%29 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %28)
%30 = icmp eq i32 %23, 1
%31 = load i32, i32* %28
%32 = icmp eq i32 %31, 0
%33 = select i1 %30, i1 %32, i1 false
%34 = select i1 %33, i32 1, i32 %22
%35 = icmp eq i32 %31, 0
%36 = icmp eq i32 %23, 0
%37 = select i1 %35, i1 %36, i1 false
%38 = select i1 %37, i32 1, i32 %23
%39 = icmp eq i32 %38, 1
%40 = icmp eq i32 %34, 0
%41 = select i1 %39, i1 %40, i1 false
%42 = select i1 %41, i32 %31, i32 0
%43 = add nsw i32 %42, %24
%44 = load i32, i32* %1
%45 = zext i32 %44 to i64
%46 = icmp ult i64 %25, %45
br i1 %46, label %20, label %17
}