#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 */
float floor(float);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int sqrt(int);
int main() {
  int num;
  printf("Enter a positive number: ");
  scanf("%d", &num);
  int a = 1, b = 1;
  int c = (num * -2);
  int d = (b * b) - (4 * a * c);
  if (d < 0) {
    printf("The number is a triangular number");
    return 0;
  }
  float root1 = ((-b) + sqrt(d)) / (2 * a);
  float root2 = ((-b) - sqrt(d)) / (2 * a);
  if (root1 > 0 && floor(root1) == root1)
    printf("The number is a triangular number");
  else if (root2 > 0 && floor(root2) == root2)
    printf("The number is a triangular number");
  else
    printf("The number is not a triangular number");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb8(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
imul   $0xfffffffe,-0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
imul   -0x14(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11b8 <main+0x78>
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1293 <main+0x153>
xor    %eax,%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <sqrt@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x1c(%rbp)
xor    %eax,%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <sqrt@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x1c(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    1246 <main+0x106>
movss  -0x1c(%rbp),%xmm0
call   1060 <floor@plt>
ucomiss -0x1c(%rbp),%xmm0
jne    1246 <main+0x106>
jp     1246 <main+0x106>
lea    0xde1(%rip),%rdi
call   1030 <printf@plt>
jmp    1293 <main+0x153>
movss  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    1282 <main+0x142>
movss  -0x20(%rbp),%xmm0
call   1060 <floor@plt>
ucomiss -0x20(%rbp),%xmm0
jne    1282 <main+0x142>
jp     1282 <main+0x142>
lea    0xda5(%rip),%rdi
call   1030 <printf@plt>
jmp    128e <main+0x14e>
lea    0xdb6(%rip),%rdi
call   1030 <printf@plt>
jmp    1293 <main+0x153>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1030 <printf@plt>
lea    0xecf(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%ebp
shl    $0x3,%ebp
or     $0x1,%ebp
lea    0xeb7(%rip),%rbx
js     1194 <main+0x64>
mov    %ebp,%edi
call   1050 <sqrt@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1050 <sqrt@plt>
cmp    $0x2,%r14d
jg     1194 <main+0x64>
cmp    $0xfffffffe,%eax
lea    0xe94(%rip),%rax
lea    0xeaf(%rip),%rbx
cmovl  %rax,%rbx
mov    %rbx,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Enter a positive number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"The number is a triangular number\00"
@.str.3 = [38 x i8] c"The number is not a triangular number\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca float
%8 = alloca float
store i32 0, i32* %1
%9 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, 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)
store i32 1, i32* %3
store i32 1, i32* %4
%11 = load i32, i32* %2
%12 = mul nsw i32 %11, -2
store i32 %12, i32* %5
%13 = load i32, i32* %4
%14 = load i32, i32* %4
%15 = mul nsw i32 %13, %14
%16 = load i32, i32* %3
%17 = mul nsw i32 4, %16
%18 = load i32, i32* %5
%19 = mul nsw i32 %17, %18
%20 = sub nsw i32 %15, %19
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %0
%24 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %66
25: ; preds = %0
%26 = load i32, i32* %4
%27 = sub nsw i32 0, %26
%28 = load i32, i32* %6
%29 = call i32 @sqrt(i32 %28)
%30 = add nsw i32 %27, %29
%31 = load i32, i32* %3
%32 = mul nsw i32 2, %31
%33 = sdiv i32 %30, %32
%34 = sitofp i32 %33 to float
store float %34, float* %7
%35 = load i32, i32* %4
%36 = sub nsw i32 0, %35
%37 = load i32, i32* %6
%38 = call i32 @sqrt(i32 %37)
%39 = sub nsw i32 %36, %38
%40 = load i32, i32* %3
%41 = mul nsw i32 2, %40
%42 = sdiv i32 %39, %41
%43 = sitofp i32 %42 to float
store float %43, float* %8
%44 = load float, float* %7
%45 = fcmp ogt float %44, 0.000000e+00
br i1 %45, label %46, label %53
46: ; preds = %25
%47 = load float, float* %7
%48 = call float @floor(float %47)
%49 = load float, float* %7
%50 = fcmp oeq float %48, %49
br i1 %50, label %51, label %53
51: ; preds = %46
%52 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %66
53: ; preds = %46, %25
%54 = load float, float* %8
%55 = fcmp ogt float %54, 0.000000e+00
br i1 %55, label %56, label %63
56: ; preds = %53
%57 = load float, float* %8
%58 = call float @floor(float %57)
%59 = load float, float* %8
%60 = fcmp oeq float %58, %59
br i1 %60, label %61, label %63
61: ; preds = %56
%62 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %65
63: ; preds = %56, %53
%64 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %65
65: ; preds = %63, %61
br label %66
66: ; preds = %23, %65, %51
%67 = load i32, i32* %1
ret i32 %67
}

LLVM IR (-O2):
@.str = [26 x i8] c"Enter a positive number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"The number is a triangular number\00"
@.str.3 = [38 x i8] c"The number is not a triangular number\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 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 = shl i32 %5, 3
%7 = or i32 %6, 1
%8 = icmp slt i32 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %0
%10 = call i32 @sqrt(i32 %7)
%11 = call i32 @sqrt(i32 %7)
%12 = icmp sgt i32 %10, 2
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = icmp slt i32 %11, -2
%15 = select i1 %14, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0)
br label %16
16: ; preds = %13, %9, %0
%17 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), %0 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), %9 ], [ %15, %13 ]
%18 = call i32 @printf(i8* dereferenceable(1) %17)
ret i32 0
}