int main() {
  int num, sum, count;
  num = 1;
  sum = 0;
  count = 0;
  while (num != 0) {
    printf("Input a number:\n");
    scanf("%d", &num);
    if (num > 0) {
      sum += num;
      ++count;
    }
  }
  printf("%s%d,%s%d\n", "sum=", sum, "count=", count);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     118f <main+0x6f>
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeae(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jle    118a <main+0x6a>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1144 <main+0x24>
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%r8d
lea    0xe77(%rip),%rdi
lea    0xe7b(%rip),%rsi
lea    0xe79(%rip),%rcx
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0x1,0xc(%rsp)
lea    0xecf(%rip),%r14
lea    0xeae(%rip),%r15
lea    0xc(%rsp),%r12
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
xor    %ecx,%ecx
test   %eax,%eax
mov    $0x0,%edx
cmovg  %eax,%edx
setg   %cl
add    %edx,%ebp
add    %ecx,%ebx
test   %eax,%eax
jne    1160 <main+0x30>
lea    0xe6c(%rip),%rdi
lea    0xe70(%rip),%rsi
lea    0xe6e(%rip),%rcx
mov    %ebp,%edx
mov    %ebx,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Input a number:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"%s%d,%s%d\0A\00"
@.str.3 = [5 x i8] c"sum=\00"
@.str.4 = [7 x i8] c"count=\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %19, %0
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = add nsw i32 %15, %14
store i32 %16, i32* %3
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %19
19: ; preds = %13, %8
br label %5
20: ; preds = %5
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [11 x i8] c"%s%d,%s%d\0A\00"
@.str.3 = [5 x i8] c"sum=\00"
@.str.4 = [7 x i8] c"count=\00"
@str = [16 x i8] c"Input a number:\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 1, i32* %1
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ 0, %0 ], [ %13, %3 ]
%5 = phi i32 [ 0, %0 ], [ %11, %3 ]
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
%10 = select i1 %9, i32 %8, i32 0
%11 = add nuw nsw i32 %10, %5
%12 = zext i1 %9 to i32
%13 = add nuw nsw i32 %4, %12
%14 = icmp eq i32 %8, 0
br i1 %14, label %15, label %3
15: ; preds = %3
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %13)
ret i32 0
}