#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 *, int *);
void main() {
  int i = 0, j;
  printf("Please enter a positive integer: ");
  scanf("%d", &j);
  while (j < 0) {
    printf("The number you entered is not positive. Please enter a positive "
           "integer: ");
    scanf("%d", &j);
  }
  while (j > 0) {
    i = i + j;
    printf("Please enter a positive integer: ");
    scanf("%d", &j);
  }
  printf("The sum of the numbers you entered is %d.", i);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xef5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebc(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    117a <main+0x5a>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe94(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
jmp    114d <main+0x2d>
jmp    117f <main+0x5f>
cmpl   $0x0,-0x8(%rbp)
jle    11b5 <main+0x95>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe59(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
jmp    117f <main+0x5f>
mov    -0x4(%rbp),%esi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xefc(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
jns    118d <main+0x6d>
lea    0xeab(%rip),%r14
lea    0xea1(%rip),%r15
lea    0x4(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
js     1170 <main+0x50>
test   %eax,%eax
je     11cf <main+0xaf>
lea    0xe93(%rip),%r14
lea    0xe61(%rip),%r15
lea    0x4(%rsp),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
add    %eax,%ebx
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
jg     11b0 <main+0x90>
lea    0xe77(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Please enter a positive integer: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [74 x i8] c"The number you entered is not positive. Please enter a positive integer: \00"
@.str.3 = [42 x i8] c"The sum of the numbers you entered is %d.\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 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* %2)
br label %5
5: ; preds = %8, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %5
11: ; preds = %5
br label %12
12: ; preds = %15, %11
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = load i32, i32* %1
%17 = load i32, i32* %2
%18 = add nsw i32 %16, %17
store i32 %18, i32* %1
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %12
21: ; preds = %12
%22 = load i32, i32* %1
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %22)
ret void
}

LLVM IR (-O2):
@.str = [34 x i8] c"Please enter a positive integer: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [74 x i8] c"The number you entered is not positive. Please enter a positive integer: \00"
@.str.3 = [42 x i8] c"The sum of the numbers you entered is %d.\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 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 = load i32, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %10, %0
%8 = phi i32 [ %5, %0 ], [ %13, %10 ]
%9 = icmp eq i32 %8, 0
br i1 %9, label %23, label %15
10: ; preds = %0, %10
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%13 = load i32, i32* %1
%14 = icmp slt i32 %13, 0
br i1 %14, label %10, label %7
15: ; preds = %7, %15
%16 = phi i32 [ %18, %15 ], [ 0, %7 ]
%17 = phi i32 [ %21, %15 ], [ %8, %7 ]
%18 = add nsw i32 %16, %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%21 = load i32, i32* %1
%22 = icmp sgt i32 %21, 0
br i1 %22, label %15, label %23
23: ; preds = %15, %7
%24 = phi i32 [ 0, %7 ], [ %18, %15 ]
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %24)
ret void
}