#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 */
scalar_t__ abs(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int pre = 0, input = 0, sum = 0, inc = 0, pattern = 1;
  printf("enter a number: ");
  scanf("%d", &pre);
  printf("enter a number: ");
  scanf("%d", &input);
  sum += abs(input - pre);
  inc += 2;
  input > pre ? (pattern = 1) : (pattern = -1);
  pre = input;
  int done = 0;
  while (!done) {
    printf("enter a number: ");
    scanf("%d", &input);
    if (input == pre) {
    } else if (input > pre && pattern == 1) {
      sum += input - pre;
      inc++;
      pre = input;
    } else if (input < pre && pattern == -1) {
      printf("here: ");
      sum += pre - input;
      inc++;
      pre = input;
    } else
      done = !done;
  }
  printf("average ");
  pattern == 1 ? printf("increment") : printf("decrement");
  printf(" is %d/%d = %.2f", sum, inc, (sum) / (double)(inc));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9a(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7c(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%edi
sub    -0x8(%rbp),%edi
call   1030 <abs@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    11d7 <main+0xa7>
movl   $0x1,-0x18(%rbp)
jmp    11de <main+0xae>
movl   $0xffffffff,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1201 <main+0xd1>
jmp    12ca <main+0x19a>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdfb(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    1230 <main+0x100>
jmp    12c5 <main+0x195>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    1266 <main+0x136>
cmpl   $0x1,-0x18(%rbp)
jne    1266 <main+0x136>
mov    -0xc(%rbp),%eax
sub    -0x8(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    12c0 <main+0x190>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12aa <main+0x17a>
cmpl   $0xffffffff,-0x18(%rbp)
jne    12aa <main+0x17a>
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    12bb <main+0x18b>
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
jmp    12c0 <main+0x190>
jmp    12c5 <main+0x195>
jmp    11eb <main+0xbb>
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x1,-0x18(%rbp)
jne    12f5 <main+0x1c5>
lea    0xd3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1303 <main+0x1d3>
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
cvtsi2sdl -0x10(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xd1a(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xeab(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeab(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <scanf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <scanf@plt>
mov    0x10(%rsp),%edi
sub    0xc(%rsp),%edi
call   1030 <abs@plt>
mov    %rax,%r14
mov    0x10(%rsp),%r13d
mov    0xc(%rsp),%eax
mov    %eax,0x14(%rsp)
cmp    %eax,%r13d
setle  0xb(%rsp)
mov    $0x2,%r12d
mov    %r13d,%eax
jmp    11ca <main+0x9a>
nopl   (%rax)
add    %eax,%r14d
sub    %ecx,%r14d
add    $0x1,%r12d
mov    %eax,0xc(%rsp)
xchg   %ax,%ax
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <scanf@plt>
mov    0x10(%rsp),%eax
mov    0xc(%rsp),%ecx
cmp    %ecx,%eax
je     11d0 <main+0xa0>
jle    11fa <main+0xca>
cmp    0x14(%rsp),%r13d
jg     11c0 <main+0x90>
cmp    %ecx,%eax
setl   %al
and    0xb(%rsp),%al
cmp    $0x1,%al
jne    1227 <main+0xf7>
lea    0xe06(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%eax
add    0xc(%rsp),%r14d
sub    %eax,%r14d
add    $0x1,%r12d
jmp    11ca <main+0x9a>
lea    0xded(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    0x14(%rsp),%r13d
lea    0xde3(%rip),%rax
lea    0xde6(%rip),%rdi
cmovg  %rax,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cvtsi2sd %r14d,%xmm0
cvtsi2sd %r12d,%xmm1
divsd  %xmm1,%xmm0
lea    0xdd0(%rip),%rdi
mov    %r14d,%esi
mov    %r12d,%edx
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"enter a number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [7 x i8] c"here: \00"
@.str.3 = [9 x i8] c"average \00"
@.str.4 = [10 x i8] c"increment\00"
@.str.5 = [10 x i8] c"decrement\00"
@.str.6 = [17 x i8] c" is %d/%d = %.2f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 1, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %3
%13 = load i32, i32* %2
%14 = sub nsw i32 %12, %13
%15 = call i64 @abs(i32 %14)
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = add nsw i64 %17, %15
%19 = trunc i64 %18 to i32
store i32 %19, i32* %4
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 2
store i32 %21, i32* %5
%22 = load i32, i32* %3
%23 = load i32, i32* %2
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %0
store i32 1, i32* %6
br label %27
26: ; preds = %0
store i32 -1, i32* %6
br label %27
27: ; preds = %26, %25
%28 = phi i32 [ 1, %25 ], [ -1, %26 ]
%29 = load i32, i32* %3
store i32 %29, i32* %2
store i32 0, i32* %7
br label %30
30: ; preds = %81, %27
%31 = load i32, i32* %7
%32 = icmp ne i32 %31, 0
%33 = xor i1 %32, true
br i1 %33, label %34, label %82
34: ; preds = %30
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%37 = load i32, i32* %3
%38 = load i32, i32* %2
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %41
40: ; preds = %34
br label %81
41: ; preds = %34
%42 = load i32, i32* %3
%43 = load i32, i32* %2
%44 = icmp sgt i32 %42, %43
br i1 %44, label %45, label %57
45: ; preds = %41
%46 = load i32, i32* %6
%47 = icmp eq i32 %46, 1
br i1 %47, label %48, label %57
48: ; preds = %45
%49 = load i32, i32* %3
%50 = load i32, i32* %2
%51 = sub nsw i32 %49, %50
%52 = load i32, i32* %4
%53 = add nsw i32 %52, %51
store i32 %53, i32* %4
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
store i32 %55, i32* %5
%56 = load i32, i32* %3
store i32 %56, i32* %2
br label %80
57: ; preds = %45, %41
%58 = load i32, i32* %3
%59 = load i32, i32* %2
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %74
61: ; preds = %57
%62 = load i32, i32* %6
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %74
64: ; preds = %61
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%66 = load i32, i32* %2
%67 = load i32, i32* %3
%68 = sub nsw i32 %66, %67
%69 = load i32, i32* %4
%70 = add nsw i32 %69, %68
store i32 %70, i32* %4
%71 = load i32, i32* %5
%72 = add nsw i32 %71, 1
store i32 %72, i32* %5
%73 = load i32, i32* %3
store i32 %73, i32* %2
br label %79
74: ; preds = %61, %57
%75 = load i32, i32* %7
%76 = icmp ne i32 %75, 0
%77 = xor i1 %76, true
%78 = zext i1 %77 to i32
store i32 %78, i32* %7
br label %79
79: ; preds = %74, %64
br label %80
80: ; preds = %79, %48
br label %81
81: ; preds = %80, %40
br label %30
82: ; preds = %30
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%84 = load i32, i32* %6
%85 = icmp eq i32 %84, 1
br i1 %85, label %86, label %88
86: ; preds = %82
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %90
88: ; preds = %82
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %90
90: ; preds = %88, %86
%91 = phi i32 [ %87, %86 ], [ %89, %88 ]
%92 = load i32, i32* %4
%93 = load i32, i32* %5
%94 = load i32, i32* %4
%95 = sitofp i32 %94 to double
%96 = load i32, i32* %5
%97 = sitofp i32 %96 to double
%98 = fdiv double %95, %97
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %92, i32 %93, double %98)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"enter a number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [7 x i8] c"here: \00"
@.str.3 = [9 x i8] c"average \00"
@.str.4 = [10 x i8] c"increment\00"
@.str.5 = [10 x i8] c"decrement\00"
@.str.6 = [17 x i8] c" is %d/%d = %.2f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = load i32, i32* %1
%11 = sub nsw i32 %9, %10
%12 = call i64 @abs(i32 %11)
%13 = trunc i64 %12 to i32
%14 = load i32, i32* %2
%15 = load i32, i32* %1
%16 = icmp sgt i32 %14, %15
%17 = xor i1 %16, true
br label %18
18: ; preds = %34, %0
%19 = phi i32 [ %35, %34 ], [ %14, %0 ]
%20 = phi i32 [ %37, %34 ], [ 2, %0 ]
%21 = phi i32 [ %36, %34 ], [ %13, %0 ]
store i32 %19, i32* %1
br label %22
22: ; preds = %18, %22
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%25 = load i32, i32* %2
%26 = load i32, i32* %1
%27 = icmp eq i32 %25, %26
br i1 %27, label %22, label %28
28: ; preds = %22
%29 = icmp sgt i32 %25, %26
%30 = select i1 %29, i1 %16, i1 false
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = add i32 %25, %21
%33 = sub i32 %32, %26
br label %34
34: ; preds = %31, %41
%35 = phi i32 [ %44, %41 ], [ %25, %31 ]
%36 = phi i32 [ %46, %41 ], [ %33, %31 ]
%37 = add nuw nsw i32 %20, 1
br label %18
38: ; preds = %28
%39 = icmp slt i32 %25, %26
%40 = select i1 %39, i1 %17, i1 false
br i1 %40, label %41, label %47
41: ; preds = %38
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* %1
%44 = load i32, i32* %2
%45 = add i32 %43, %21
%46 = sub i32 %45, %44
br label %34
47: ; preds = %38
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%49 = select i1 %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %49)
%51 = sitofp i32 %21 to double
%52 = sitofp i32 %20 to double
%53 = fdiv double %51, %52
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %21, i32 %20, double %53)
ret i32 0
}