#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 */
double atof(char *);
int /*<<< orphan*/ cos(double);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int strlen(char *);
void my_cos(void) {
  double arg;
  int i;
  char str[16] = {0};
  printf("enter argument of the function cos: ");
  if (fgets(str, 16, stdin) == NULL)
    return;
  for (i = 0; i < strlen(str) - 1; i++) {
    if (str[i] < 0x30 || str[i] > 0x39) {
      if (str[i] != 0x2E) {
        printf("entered not correct symbol\n");
        return;
      }
    }
  }
  arg = atof(str);
  printf("cos(%lf) = %lf\n", arg, cos(arg));
}


x86 assembly (clang, -O0):
<my_cos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    0x2e57(%rip),%rax
mov    (%rax),%edx
mov    $0x10,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    11ac <my_cos+0x4c>
jmp    126a <my_cos+0x10a>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1233 <my_cos+0xd3>
movslq -0xc(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x30,%eax
jl     11f6 <my_cos+0x96>
movslq -0xc(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x39,%eax
jle    1220 <my_cos+0xc0>
movslq -0xc(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x2e,%eax
je     121b <my_cos+0xbb>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    126a <my_cos+0x10a>
jmp    1220 <my_cos+0xc0>
jmp    1225 <my_cos+0xc5>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b3 <my_cos+0x53>
lea    -0x20(%rbp),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1080 <cos@plt>
movsd  -0x30(%rbp),%xmm0
mov    %eax,%esi
lea    0xdde(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_cos>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
lea    0xe8b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x10,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     120b <my_cos+0xab>
mov    %rsp,%rdi
call   1050 <strlen@plt>
cmp    $0x2,%eax
jl     11e2 <my_cos+0x82>
xor    %ebx,%ebx
mov    %rsp,%r14
jmp    11c6 <my_cos+0x66>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
add    $0xffffffff,%eax
cltq
cmp    %rax,%rbx
jge    11e2 <my_cos+0x82>
movzbl (%rsp,%rbx,1),%eax
cmp    $0x2e,%al
je     11b0 <my_cos+0x50>
add    $0xd0,%al
cmp    $0xa,%al
jb     11b0 <my_cos+0x50>
lea    0xe5a(%rip),%rdi
call   1030 <puts@plt>
jmp    120b <my_cos+0xab>
mov    %rsp,%rdi
call   1040 <atof@plt>
movsd  %xmm0,0x10(%rsp)
call   1080 <cos@plt>
lea    0xe29(%rip),%rdi
movsd  0x10(%rsp),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1060 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [37 x i8] c"enter argument of the function cos: \00"
@stdin = global i32 0
@.str.1 = [28 x i8] c"entered not correct symbol\0A\00"
@.str.2 = [16 x i8] c"cos(%lf) = %lf\0A\00"
define void @my_cos() {
%1 = alloca double
%2 = alloca i32
%3 = alloca [16 x i8]
%4 = bitcast [16 x i8]* %3 to i8*
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32* @fgets(i8* %6, i32 16, i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %0
br label %53
11: ; preds = %0
store i32 0, i32* %2
br label %12
12: ; preds = %43, %11
%13 = load i32, i32* %2
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = sub nsw i32 %15, 1
%17 = icmp slt i32 %13, %16
br i1 %17, label %18, label %46
18: ; preds = %12
%19 = load i32, i32* %2
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp slt i32 %23, 48
br i1 %24, label %32, label %25
25: ; preds = %18
%26 = load i32, i32* %2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp sgt i32 %30, 57
br i1 %31, label %32, label %42
32: ; preds = %25, %18
%33 = load i32, i32* %2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 46
br i1 %38, label %39, label %41
39: ; preds = %32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %53
41: ; preds = %32
br label %42
42: ; preds = %41, %25
br label %43
43: ; preds = %42
%44 = load i32, i32* %2
%45 = add nsw i32 %44, 1
store i32 %45, i32* %2
br label %12
46: ; preds = %12
%47 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%48 = call double @atof(i8* %47)
store double %48, double* %1
%49 = load double, double* %1
%50 = load double, double* %1
%51 = call i32 @cos(double %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %49, i32 %51)
br label %53
53: ; preds = %46, %39, %10
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"enter argument of the function cos: \00"
@stdin = global i32 0
@.str.2 = [16 x i8] c"cos(%lf) = %lf\0A\00"
@str = [27 x i8] c"entered not correct symbol\00"
define void @my_cos() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i32* @fgets(i8* %2, i32 16, i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %30, label %7
7: ; preds = %0
%8 = call i32 @strlen(i8* %2)
%9 = icmp sgt i32 %8, 1
br i1 %9, label %15, label %26
10: ; preds = %15
%11 = call i32 @strlen(i8* %2)
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = icmp slt i64 %23, %13
br i1 %14, label %15, label %26
15: ; preds = %7, %10
%16 = phi i64 [ %23, %10 ], [ 0, %7 ]
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = add i8 %18, -48
%20 = icmp ult i8 %19, 10
%21 = icmp eq i8 %18, 46
%22 = or i1 %21, %20
%23 = add nuw nsw i64 %16, 1
br i1 %22, label %10, label %24
24: ; preds = %15
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %30
26: ; preds = %10, %7
%27 = call double @atof(i8* %2)
%28 = call i32 @cos(double %27)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %27, i32 %28)
br label %30
30: ; preds = %0, %26, %24
ret void
}