#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 *, ...);
int /*<<< orphan*/ scanf(char *, long *);
int main(void) {
  long n, sum = 0;
  printf("This program sums a series of integers.\n");
  printf("Enter integers (0 to terminate): ");
  scanf("%ld", &n);
  while (n != 0) {
    sum += n;
    scanf("%ld", &n);
  }
  printf("The sum is: %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    0xedd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef1(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmpq   $0x0,-0x10(%rbp)
je     118f <main+0x6f>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
jmp    1163 <main+0x43>
mov    -0x18(%rbp),%rsi
lea    0xeb5(%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
lea    0xef7(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec6(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     1198 <main+0x68>
xor    %ebx,%ebx
lea    0xea9(%rip),%r14
lea    0x8(%rsp),%r15
xchg   %ax,%ax
add    %rax,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%rax
test   %rax,%rax
jne    1180 <main+0x50>
lea    0xe87(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [41 x i8] c"This program sums a series of integers.\0A\00"
@.str.1 = [34 x i8] c"Enter integers (0 to terminate): \00"
@.str.2 = [4 x i8] c"%ld\00"
@.str.3 = [17 x i8] c"The sum is: %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %3
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %2)
br label %7
7: ; preds = %10, %0
%8 = load i64, i64* %2
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = load i64, i64* %2
%12 = load i64, i64* %3
%13 = add nsw i64 %12, %11
store i64 %13, i64* %3
%14 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %2)
br label %7
15: ; preds = %7
%16 = load i64, i64* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i64 %16)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [34 x i8] c"Enter integers (0 to terminate): \00"
@.str.2 = [4 x i8] c"%ld\00"
@.str.3 = [17 x i8] c"The sum is: %ld\0A\00"
@str = [40 x i8] c"This program sums a series of integers.\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%6 = load i64, i64* %1
%7 = icmp eq i64 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %0, %8
%9 = phi i64 [ %13, %8 ], [ %6, %0 ]
%10 = phi i64 [ %11, %8 ], [ 0, %0 ]
%11 = add nsw i64 %9, %10
%12 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%13 = load i64, i64* %1
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %8
15: ; preds = %8, %0
%16 = phi i64 [ 0, %0 ], [ %11, %8 ]
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i64 %16)
ret i32 0
}