#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 *, ...);
void checkIfTribonacci(int media) {
  const int number = media;
  int a = 0;
  int b = 1;
  int c = 1;
  int result = 0;
  if (media == 0) {
    result = a;
    printf("\nbase case\n");
  }
  if (media == 1) {
    result = b;
    printf("\nbase case\n");
  }
  if (media == 2) {
    result = c;
    printf("\nbase case\n");
  }
  while (media > 2) {
    result = a + b + c;
    a = b;
    b = c;
    c = result;
    media--;
    if (result == number) {
      printf("\n%d is part of Tribonacci number\n", number);
      break;
    }
    if (media == 3) {
      printf(" I'm sorry  isn't in the series!");
    }
  }
}


x86 assembly (clang, -O0):
<checkIfTribonacci>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    115b <checkIfTribonacci+0x4b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x4(%rbp)
jne    1179 <checkIfTribonacci+0x69>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x2,-0x4(%rbp)
jne    1197 <checkIfTribonacci+0x87>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119c <checkIfTribonacci+0x8c>
cmpl   $0x2,-0x4(%rbp)
jle    120c <checkIfTribonacci+0xfc>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    11ef <checkIfTribonacci+0xdf>
mov    -0x8(%rbp),%esi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120c <checkIfTribonacci+0xfc>
cmpl   $0x3,-0x4(%rbp)
jne    1207 <checkIfTribonacci+0xf7>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119c <checkIfTribonacci+0x8c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkIfTribonacci>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
je     113d <checkIfTribonacci+0x1d>
mov    %edi,%r15d
cmp    $0x1,%edi
je     113d <checkIfTribonacci+0x1d>
test   %r15d,%r15d
jne    1157 <checkIfTribonacci+0x37>
lea    0xeff(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
cmp    $0x3,%r15d
jl     11af <checkIfTribonacci+0x8f>
lea    0x1(%r15),%ebp
mov    $0x1,%ebx
lea    0xeb5(%rip),%r14
mov    $0x1,%r12d
xor    %r13d,%r13d
jmp    1188 <checkIfTribonacci+0x68>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
cmp    $0x3,%ebp
jbe    11af <checkIfTribonacci+0x8f>
mov    %r13d,%eax
mov    %r12d,%r13d
mov    %ebx,%r12d
add    %r13d,%eax
mov    %eax,%ebx
add    %r12d,%ebx
cmp    %r15d,%ebx
je     11be <checkIfTribonacci+0x9e>
cmp    $0x5,%ebp
jne    1180 <checkIfTribonacci+0x60>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1180 <checkIfTribonacci+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe3b(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"\0Abase case\0A\00"
@.str.1 = [34 x i8] c"\0A%d is part of Tribonacci number\0A\00"
@.str.2 = [33 x i8] c" I'm sorry isn't in the series!\00"
define void @checkIfTribonacci(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
%8 = load i32, i32* %2
store i32 %8, i32* %3
store i32 0, i32* %4
store i32 1, i32* %5
store i32 1, i32* %6
store i32 0, i32* %7
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* %4
store i32 %12, i32* %7
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %11, %1
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %5
store i32 %18, i32* %7
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %17, %14
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 2
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %6
store i32 %24, i32* %7
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %23, %20
br label %27
27: ; preds = %52, %26
%28 = load i32, i32* %2
%29 = icmp sgt i32 %28, 2
br i1 %29, label %30, label %53
30: ; preds = %27
%31 = load i32, i32* %4
%32 = load i32, i32* %5
%33 = add nsw i32 %31, %32
%34 = load i32, i32* %6
%35 = add nsw i32 %33, %34
store i32 %35, i32* %7
%36 = load i32, i32* %5
store i32 %36, i32* %4
%37 = load i32, i32* %6
store i32 %37, i32* %5
%38 = load i32, i32* %7
store i32 %38, i32* %6
%39 = load i32, i32* %2
%40 = add nsw i32 %39, -1
store i32 %40, i32* %2
%41 = load i32, i32* %7
%42 = load i32, i32* %3
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %47
44: ; preds = %30
%45 = load i32, i32* %3
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %45)
br label %53
47: ; preds = %30
%48 = load i32, i32* %2
%49 = icmp eq i32 %48, 3
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %50, %47
br label %27
53: ; preds = %44, %27
ret void
}

LLVM IR (-O2):
@.str.1 = [34 x i8] c"\0A%d is part of Tribonacci number\0A\00"
@.str.2 = [33 x i8] c" I'm sorry isn't in the series!\00"
@str.4 = [11 x i8] c"\0Abase case\00"
define void @checkIfTribonacci(i32 %0) {
switch i32 %0, label %8 [
i32 0, label %2
i32 1, label %4
i32 2, label %6
]
2: ; preds = %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.4, i64 0, i64 0))
br label %27
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.4, i64 0, i64 0))
br label %27
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.4, i64 0, i64 0))
br label %27
8: ; preds = %1
%9 = icmp sgt i32 %0, 2
br i1 %9, label %10, label %27
10: ; preds = %8, %25
%11 = phi i32 [ %16, %25 ], [ 1, %8 ]
%12 = phi i32 [ %11, %25 ], [ 1, %8 ]
%13 = phi i32 [ %12, %25 ], [ 0, %8 ]
%14 = phi i32 [ %17, %25 ], [ %0, %8 ]
%15 = add nsw i32 %12, %13
%16 = add nsw i32 %15, %11
%17 = add nsw i32 %14, -1
%18 = icmp eq i32 %16, %0
br i1 %18, label %19, label %21
19: ; preds = %10
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %27
21: ; preds = %10
%22 = icmp eq i32 %17, 3
br i1 %22, label %23, label %25
23: ; preds = %21
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %21
%26 = icmp ugt i32 %14, 3
br i1 %26, label %10, label %27
27: ; preds = %25, %6, %2, %4, %8, %19
ret void
}