#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 */
typedef int uint64_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int type;
  printf("Pretende usar numero maximo de valores(1) ou valor maximo(2)? ");
  scanf("%d", &type);
  uint64_t until;
  if (type == 1) {
    printf("Introduza um numero de valores da sequência: ");
    scanf("%lu", &until);
  } else {
    printf("Introduza o valor máximo: ");
    scanf("%lu", &until);
  }
  uint64_t first, second;
  for (int iterationNumber = 0;
       (type == 1 && iterationNumber < until) || type != 1; ++iterationNumber) {
    if (iterationNumber == 0) {
      second = 0;
    } else if (iterationNumber == 1) {
      first = 0;
      second = 1;
    } else {
      uint64_t temp = first;
      first = second;
      second += temp;
    }
    if (type != 1 && second > until) {
      break;
    }
    if (iterationNumber) {
      printf(", ");
    }
    printf("%lu", second);
  }
  puts(".");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeeb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    118a <main+0x5a>
lea    0xed4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xef5(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
jmp    11a8 <main+0x78>
lea    0xee4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xed2(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11ca <main+0x9a>
mov    -0x18(%rbp),%ecx
mov    $0x1,%al
cmp    -0xc(%rbp),%ecx
mov    %al,-0x1d(%rbp)
jl     11d4 <main+0xa4>
cmpl   $0x1,-0x8(%rbp)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11e4 <main+0xb4>
jmp    1283 <main+0x153>
cmpl   $0x0,-0x18(%rbp)
jne    11fa <main+0xca>
movl   $0x0,-0x14(%rbp)
jmp    1231 <main+0x101>
cmpl   $0x1,-0x18(%rbp)
jne    1217 <main+0xe7>
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    122c <main+0xfc>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1231 <main+0x101>
cmpl   $0x1,-0x8(%rbp)
je     124c <main+0x11c>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    124c <main+0x11c>
jmp    1283 <main+0x153>
cmpl   $0x0,-0x18(%rbp)
je     1264 <main+0x134>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11af <main+0x7f>
lea    0xe0a(%rip),%rdi
call   1030 <puts@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
push   %rax
lea    0xebe(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeef(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
cmpl   $0x1,(%rsp)
lea    0xedf(%rip),%rax
lea    0xf0b(%rip),%rdi
cmove  %rax,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xef5(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x1,(%rsp)
setne  %al
mov    0x4(%rsp),%ecx
jne    119b <main+0x6b>
test   %ecx,%ecx
jle    1220 <main+0xf0>
mov    $0x1,%edx
lea    0xeca(%rip),%r15
lea    0xee3(%rip),%r14
xchg   %ax,%ax
mov    %edx,%r12d
add    $0xffffffff,%edx
je     11d0 <main+0xa0>
cmp    $0x1,%edx
jne    11e0 <main+0xb0>
test   %ecx,%ecx
setle  %cl
test   %cl,%al
jne    1220 <main+0xf0>
mov    $0x1,%ebp
xor    %ebx,%ebx
jmp    11eb <main+0xbb>
nop
test   %ecx,%ecx
sets   %cl
xor    %ebx,%ebx
test   %cl,%al
je     11fd <main+0xcd>
jmp    1220 <main+0xf0>
nopl   (%rax)
add    %ebx,%ebp
cmp    %ecx,%ebp
setg   %cl
test   %cl,%al
jne    1220 <main+0xf0>
mov    %ebp,%r13d
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%ebp
mov    %r13d,%ebx
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1(%r12),%edx
cmpl   $0x1,(%rsp)
setne  %al
mov    0x4(%rsp),%ecx
jne    11b0 <main+0x80>
cmp    %ecx,%r12d
jl     11b0 <main+0x80>
lea    0xe6d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [63 x i8] c"Pretende usar numero maximo de valores(1) ou valor maximo(2)? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [47 x i8] c"Introduza um numero de valores da sequ\C3\AAncia: \00"
@.str.3 = [4 x i8] c"%lu\00"
@.str.4 = [28 x i8] c"Introduza o valor m\C3\A1ximo: \00"
@.str.5 = [3 x i8] c", \00"
@.str.6 = [2 x i8] c".\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
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 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 = load i32, i32* %2
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %3)
br label %18
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %3)
br label %18
18: ; preds = %15, %12
store i32 0, i32* %6
br label %19
19: ; preds = %62, %18
%20 = load i32, i32* %2
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* %6
%24 = load i32, i32* %3
%25 = icmp slt i32 %23, %24
br i1 %25, label %29, label %26
26: ; preds = %22, %19
%27 = load i32, i32* %2
%28 = icmp ne i32 %27, 1
br label %29
29: ; preds = %26, %22
%30 = phi i1 [ true, %22 ], [ %28, %26 ]
br i1 %30, label %31, label %65
31: ; preds = %29
%32 = load i32, i32* %6
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %31
store i32 0, i32* %5
br label %46
35: ; preds = %31
%36 = load i32, i32* %6
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %39
38: ; preds = %35
store i32 0, i32* %4
store i32 1, i32* %5
br label %45
39: ; preds = %35
%40 = load i32, i32* %4
store i32 %40, i32* %7
%41 = load i32, i32* %5
store i32 %41, i32* %4
%42 = load i32, i32* %7
%43 = load i32, i32* %5
%44 = add nsw i32 %43, %42
store i32 %44, i32* %5
br label %45
45: ; preds = %39, %38
br label %46
46: ; preds = %45, %34
%47 = load i32, i32* %2
%48 = icmp ne i32 %47, 1
br i1 %48, label %49, label %54
49: ; preds = %46
%50 = load i32, i32* %5
%51 = load i32, i32* %3
%52 = icmp sgt i32 %50, %51
br i1 %52, label %53, label %54
53: ; preds = %49
br label %65
54: ; preds = %49, %46
%55 = load i32, i32* %6
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %54
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %59
59: ; preds = %57, %54
%60 = load i32, i32* %5
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %59
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %19
65: ; preds = %53, %29
%66 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [63 x i8] c"Pretende usar numero maximo de valores(1) ou valor maximo(2)? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [47 x i8] c"Introduza um numero de valores da sequ\C3\AAncia: \00"
@.str.3 = [4 x i8] c"%lu\00"
@.str.4 = [28 x i8] c"Introduza o valor m\C3\A1ximo: \00"
@.str.5 = [3 x i8] c", \00"
@.str.6 = [2 x i8] c".\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = bitcast i32* %2 to i8*
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 1
%9 = select i1 %8, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %9)
%11 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %1
%13 = icmp ne i32 %12, 1
%14 = load i32, i32* %2
%15 = icmp sgt i32 %14, 0
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %17, label %47
17: ; preds = %0, %37
%18 = phi i32 [ %44, %37 ], [ %14, %0 ]
%19 = phi i1 [ %43, %37 ], [ %13, %0 ]
%20 = phi i32 [ %41, %37 ], [ 0, %0 ]
%21 = phi i32 [ %39, %37 ], [ undef, %0 ]
%22 = phi i32 [ %38, %37 ], [ undef, %0 ]
switch i32 %20, label %23 [
i32 0, label %27
i32 1, label %30
]
23: ; preds = %17
%24 = add nsw i32 %21, %22
%25 = icmp sgt i32 %24, %18
%26 = select i1 %19, i1 %25, i1 false
br i1 %26, label %47, label %33
27: ; preds = %17
%28 = icmp slt i32 %18, 0
%29 = select i1 %19, i1 %28, i1 false
br i1 %29, label %47, label %37
30: ; preds = %17
%31 = icmp slt i32 %18, 1
%32 = select i1 %19, i1 %31, i1 false
br i1 %32, label %47, label %33
33: ; preds = %23, %30
%34 = phi i32 [ 0, %30 ], [ %21, %23 ]
%35 = phi i32 [ 1, %30 ], [ %24, %23 ]
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %27, %33
%38 = phi i32 [ %34, %33 ], [ %22, %27 ]
%39 = phi i32 [ %35, %33 ], [ 0, %27 ]
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = add nuw nsw i32 %20, 1
%42 = load i32, i32* %1
%43 = icmp ne i32 %42, 1
%44 = load i32, i32* %2
%45 = icmp slt i32 %41, %44
%46 = select i1 %43, i1 true, i1 %45
br i1 %46, label %17, label %47
47: ; preds = %23, %37, %30, %27, %0
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}