#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*/ printf(char *, ...);
scalar_t__ scanf(char *, int *);
int main(void) {
  int i, n, r, t, max;
  while (scanf("%d", &n) && n != 0) {
    r = 0;
    max = 0;
    for (i = 0; i < n; i++) {
      scanf("%d ", &t);
      if (r + t < 0)
        r = 0;
      else
        r += t;
      if (r > max)
        max = r;
    }
    if (max > 0)
      printf("The maximum winning streak is %d.\n", max);
    else
      printf("Losing streak.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     115b <main+0x3b>
cmpl   $0x0,-0xc(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    116b <main+0x4b>
jmp    1218 <main+0xf8>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e5 <main+0xc5>
lea    0xe70(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
cmp    $0x0,%eax
jge    11b7 <main+0x97>
movl   $0x0,-0x10(%rbp)
jmp    11c0 <main+0xa0>
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    11d2 <main+0xb2>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11d7 <main+0xb7>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1180 <main+0x60>
cmpl   $0x0,-0x18(%rbp)
jle    1205 <main+0xe5>
mov    -0x18(%rbp),%esi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1213 <main+0xf3>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    112f <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
push   %rax
lea    0xebe(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
test   %rax,%rax
je     11e7 <main+0xb7>
mov    (%rsp),%eax
test   %eax,%eax
je     11e7 <main+0xb7>
lea    0xe9e(%rip),%r14
lea    0x4(%rsp),%rbx
xor    %r12d,%r12d
nopl   (%rax)
test   %eax,%eax
jle    11c0 <main+0x90>
xor    %r15d,%r15d
xor    %r13d,%r13d
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
add    0x4(%rsp),%r13d
cmovs  %r12d,%r13d
cmp    %r15d,%r13d
cmova  %r13d,%r15d
add    $0x1,%ebp
cmp    (%rsp),%ebp
jl     1180 <main+0x50>
test   %r15d,%r15d
je     11c0 <main+0x90>
lea    0xe58(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11cc <main+0x9c>
nopl   0x0(%rax,%rax,1)
lea    0xe63(%rip),%rdi
call   1030 <puts@plt>
lea    0xe2d(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
test   %rax,%rax
je     11e7 <main+0xb7>
mov    (%rsp),%eax
test   %eax,%eax
jne    1170 <main+0x40>
xor    %eax,%eax
add    $0x8,%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 = [4 x i8] c"%d \00"
@.str.2 = [35 x i8] c"The maximum winning streak is %d.\0A\00"
@.str.3 = [16 x i8] c"Losing streak.\0A\00"
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 = %49, %0
%8 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
br label %13
13: ; preds = %10, %7
%14 = phi i1 [ false, %7 ], [ %12, %10 ]
br i1 %14, label %15, label %50
15: ; preds = %13
store i32 0, i32* %4
store i32 0, i32* %6
store i32 0, i32* %2
br label %16
16: ; preds = %38, %15
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %41
20: ; preds = %16
%21 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = add nsw i32 %22, %23
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20
store i32 0, i32* %4
br label %31
27: ; preds = %20
%28 = load i32, i32* %5
%29 = load i32, i32* %4
%30 = add nsw i32 %29, %28
store i32 %30, i32* %4
br label %31
31: ; preds = %27, %26
%32 = load i32, i32* %4
%33 = load i32, i32* %6
%34 = icmp sgt i32 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = load i32, i32* %4
store i32 %36, i32* %6
br label %37
37: ; preds = %35, %31
br label %38
38: ; preds = %37
%39 = load i32, i32* %2
%40 = add nsw i32 %39, 1
store i32 %40, i32* %2
br label %16
41: ; preds = %16
%42 = load i32, i32* %6
%43 = icmp sgt i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i32, i32* %6
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %45)
br label %49
47: ; preds = %41
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47, %44
br label %7
50: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [35 x i8] c"The maximum winning streak is %d.\0A\00"
@str = [15 x i8] c"Losing streak.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = icmp ne i64 %5, 0
%7 = load i32, i32* %1
%8 = icmp ne i32 %7, 0
%9 = select i1 %6, i1 %8, i1 false
br i1 %9, label %10, label %39
10: ; preds = %0, %33
%11 = phi i32 [ %36, %33 ], [ %7, %0 ]
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %31
13: ; preds = %10, %13
%14 = phi i32 [ %23, %13 ], [ 0, %10 ]
%15 = phi i32 [ %21, %13 ], [ 0, %10 ]
%16 = phi i32 [ %24, %13 ], [ 0, %10 ]
%17 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%18 = load i32, i32* %2
%19 = add nsw i32 %18, %15
%20 = icmp sgt i32 %19, 0
%21 = select i1 %20, i32 %19, i32 0
%22 = icmp ugt i32 %21, %14
%23 = select i1 %22, i32 %21, i32 %14
%24 = add nuw nsw i32 %16, 1
%25 = load i32, i32* %1
%26 = icmp slt i32 %24, %25
br i1 %26, label %13, label %27
27: ; preds = %13
%28 = icmp eq i32 %23, 0
br i1 %28, label %31, label %29
29: ; preds = %27
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %23)
br label %33
31: ; preds = %10, %27
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %33
33: ; preds = %31, %29
%34 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%35 = icmp ne i64 %34, 0
%36 = load i32, i32* %1
%37 = icmp ne i32 %36, 0
%38 = select i1 %35, i1 %37, i1 false
br i1 %38, label %10, label %39
39: ; preds = %33, %0
ret i32 0
}