#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 */
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, int *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/);
main() {
  int i;
  int sum = 0;
  char ch;
  printf("Enter a sequence of integers:  ");
  while (scanf("%d", &i) == 1) {
    sum += i;
    while ((ch = getchar()) == ' ')
      ;
    if (ch == '\n')
      break;
    ungetc(ch, stdin);
  }
  printf("The sum of the integers is: %d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    11cc <main+0x8c>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0xd(%rbp)
movsbl %al,%eax
cmp    $0x20,%eax
jne    11a1 <main+0x61>
jmp    1186 <main+0x46>
movsbl -0xd(%rbp),%eax
cmp    $0xa,%eax
jne    11b3 <main+0x73>
jmp    11cc <main+0x8c>
mov    -0xd(%rbp),%al
mov    0x2e2b(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1050 <ungetc@plt>
jmp    1164 <main+0x24>
mov    -0xc(%rbp),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeb1(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    11bb <main+0x7b>
mov    0x2e73(%rip),%r12
lea    0xea4(%rip),%r14
lea    0x4(%rsp),%r15
xor    %ebx,%ebx
add    0x4(%rsp),%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0x20,%al
je     1190 <main+0x50>
cmp    $0xa,%al
je     11bb <main+0x7b>
mov    (%r12),%esi
movsbl %al,%edi
call   1050 <ungetc@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
je     1183 <main+0x43>
lea    0xe61(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Enter a sequence of integers: \00"
@.str.1 = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.2 = [32 x i8] c"The sum of the integers is: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %23, %0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %27
9: ; preds = %6
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = add nsw i32 %11, %10
store i32 %12, i32* %3
br label %13
13: ; preds = %17, %9
%14 = call signext i8 (...) @getchar()
store i8 %14, i8* %4
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 32
br i1 %16, label %17, label %18
17: ; preds = %13
br label %13
18: ; preds = %13
%19 = load i8, i8* %4
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 10
br i1 %21, label %22, label %23
22: ; preds = %18
br label %27
23: ; preds = %18
%24 = load i8, i8* %4
%25 = load i32, i32* @stdin
%26 = call i32 @ungetc(i8 signext %24, i32 %25)
br label %6
27: ; preds = %22, %6
%28 = load i32, i32* %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"Enter a sequence of integers: \00"
@.str.1 = [3 x i8] c"%d\00"
@stdin = global i32 0
@.str.2 = [32 x i8] c"The sum of the integers is: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %17
6: ; preds = %0, %12
%7 = phi i32 [ %9, %12 ], [ 0, %0 ]
%8 = load i32, i32* %1
%9 = add nsw i32 %8, %7
br label %10
10: ; preds = %10, %6
%11 = call signext i8 (...) @getchar()
switch i8 %11, label %12 [
i8 32, label %10
i8 10, label %17
]
12: ; preds = %10
%13 = load i32, i32* @stdin
%14 = call i32 @ungetc(i8 signext %11, i32 %13)
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%16 = icmp eq i32 %15, 1
br i1 %16, label %6, label %17
17: ; preds = %12, %10, %0
%18 = phi i32 [ 0, %0 ], [ %9, %10 ], [ %9, %12 ]
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %18)
ret i32 0
}