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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebc(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
sete   %al
and    $0x1,%al
mov    %al,-0x19(%rbp)
testb  $0x1,-0x19(%rbp)
je     11ca <main+0x9a>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe77(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
mov    %al,-0x19(%rbp)
jmp    1184 <main+0x54>
mov    -0x18(%rbp),%rsi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x21(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x22(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xec1(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xef5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec9(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    11a0 <main+0x70>
lea    0xeb7(%rip),%r14
lea    0xeac(%rip),%r15
mov    %rsp,%r12
xor    %ebx,%ebx
nop
add    (%rsp),%rbx
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmp    $0x1,%eax
je     1180 <main+0x50>
lea    0xeab(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
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 = [28 x i8] c"Those integers sum to %ld.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8
store i32 0, i32* %1
store i64 0, i64* %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %2)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 1
%13 = zext i1 %12 to i8
store i8 %13, i8* %4
br label %14
14: ; preds = %17, %0
%15 = load i8, i8* %4
%16 = trunc i8 %15 to i1
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = load i64, i64* %2
%19 = load i64, i64* %3
%20 = add nsw i64 %19, %18
store i64 %20, i64* %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %2)
%23 = icmp eq i32 %22, 1
%24 = zext i1 %23 to i8
store i8 %24, i8* %4
br label %14
25: ; preds = %14
%26 = load i64, i64* %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i64 %26)
%28 = call i32 (...) @getchar()
%29 = trunc i32 %28 to i8
store i8 %29, i8* %6
%30 = call i32 (...) @getchar()
%31 = trunc i32 %30 to i8
store i8 %31, i8* %7
%32 = call i32 (...) @getchar()
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 = [28 x i8] c"Those integers sum to %ld.\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %14
7: ; preds = %0, %7
%8 = phi i64 [ %10, %7 ], [ 0, %0 ]
%9 = load i64, i64* %1
%10 = add nsw i64 %9, %8
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%13 = icmp eq i32 %12, 1
br i1 %13, label %7, label %14
14: ; preds = %7, %0
%15 = phi i64 [ 0, %0 ], [ %10, %7 ]
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i64 %15)
%17 = call i32 (...) @getchar()
%18 = call i32 (...) @getchar()
%19 = call i32 (...) @getchar()
ret i32 0
}