int main(void) {
  long num;
  long sum = 0L;
  _Bool input_is_good;
  printf("Please enter an integer to be summed ");
  printf("(q to quit): ");
  input_is_good = (scanf("%ld", &sum) == 1);
  while (input_is_good) {
    sum = sum + num;
    printf("Please enter next integer (q to quit): ");
    input_is_good = (scanf("%ld", &num) == 1);
  }
  printf("Those integer sum to %ld.\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecc(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
mov    %al,-0x19(%rbp)
testb  $0x1,-0x19(%rbp)
je     11b6 <main+0x96>
mov    -0x18(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8b(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
mov    %al,-0x19(%rbp)
jmp    1170 <main+0x50>
mov    -0x18(%rbp),%rsi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,(%rsp)
lea    0xec8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xefe(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed2(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    11c5 <main+0xa5>
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeae(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    11c5 <main+0xa5>
lea    0xe9a(%rip),%r14
lea    0xe8f(%rip),%r15
lea    0x8(%rsp),%rbx
nopl   0x0(%rax)
mov    0x8(%rsp),%rax
add    %rax,(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmp    $0x1,%eax
je     11a0 <main+0x80>
mov    (%rsp),%rsi
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Please enter an integer to be summed \00"
@.str.1 = [14 x i8] c"(q to quit): \00"
@.str.2 = [4 x i8] c"%ld\00"
@.str.3 = [40 x i8] c"Please enter next integer (q to quit): \00"
@.str.4 = [27 x i8] c"Those integer sum to %ld.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8
store i32 0, i32* %1
store i64 0, i64* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %3)
%8 = icmp eq i32 %7, 1
%9 = zext i1 %8 to i8
store i8 %9, i8* %4
br label %10
10: ; preds = %13, %0
%11 = load i8, i8* %4
%12 = trunc i8 %11 to i1
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = load i64, i64* %3
%15 = load i64, i64* %2
%16 = add nsw i64 %14, %15
store i64 %16, i64* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %2)
%19 = icmp eq i32 %18, 1
%20 = zext i1 %19 to i8
store i8 %20, i8* %4
br label %10
21: ; preds = %10
%22 = load i64, i64* %3
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i64 %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [38 x i8] c"Please enter an integer to be summed \00"
@.str.1 = [14 x i8] c"(q to quit): \00"
@.str.2 = [4 x i8] c"%ld\00"
@.str.3 = [40 x i8] c"Please enter next integer (q to quit): \00"
@.str.4 = [27 x i8] c"Those integer sum to %ld.\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = bitcast i64* %1 to i8*
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %2)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %20
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %20
13: ; preds = %9, %13
%14 = load i64, i64* %1
%15 = load i64, i64* %2
%16 = add nsw i64 %14, %15
store i64 %16, i64* %2
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%19 = icmp eq i32 %18, 1
br i1 %19, label %13, label %20
20: ; preds = %13, %9, %0
%21 = load i64, i64* %2
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i64 %21)
ret i32 0
}