#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 CLOCKS_PER_SEC;
int /*<<< orphan*/ EXIT_SUCCESS;
scalar_t__ clock();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ write_data(int, int);
char read_data_c(int usbdev, unsigned long int wait_time, int n_wait_states) {
  double start, end, time, clock_;
  clock_ = (double)clock();
  start = (double)clock() * (1000 / CLOCKS_PER_SEC);
  time = 0;
  int wait_ = 0;
  int rd = 0;
  int cont = 0;
  char response_[5] = {0, 0, 0, 0, 0};
  printf("n wait_states %d, wait_time = %d, clock = %f, clocks_per_sec = %d\n",
         n_wait_states, wait_time, clock_, CLOCKS_PER_SEC);
  while (rd < 1) {
    rd = read(usbdev, response_, 1);
    end = (double)clock() * (1000 / CLOCKS_PER_SEC);
    time = end - start;
    printf("\nwait_=%d, time %u\n start= %f, end = %f, wait_time = %d\n ",
           wait_, time, start, end, wait_time);
    cont = cont + 1;
    if (time > wait_time) {
      printf("Error: Exceeded wait time \nSending null character '~'\n");
      write_data(usbdev, 0x7e);
      wait_ = wait_ + 1;
      time = 0;
      start = (double)clock() * (1000 / CLOCKS_PER_SEC);
      if (wait_ == n_wait_states) {
        printf("Error: Esceeded wait states.. Exit\n");
        exit(EXIT_SUCCESS);
      }
    }
  }
  printf("response = %x, cont = %d\n", response_[0], cont);
  return response_[0];
}


x86 assembly (clang, -O0):
<read_data_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
cvtsi2sd %rax,%xmm0
mov    $0x3e8,%eax
mov    0x2e4d(%rip),%rcx
cltd
idivl  (%rcx)
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
lea    -0x49(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <memset@plt>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
movsd  -0x38(%rbp),%xmm0
mov    0x2dfd(%rip),%rax
mov    (%rax),%ecx
lea    0xe2c(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
cmpl   $0x1,-0x40(%rbp)
jge    1344 <read_data_c+0x1e4>
mov    -0x4(%rbp),%edi
lea    -0x49(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0x40(%rbp)
xor    %eax,%eax
mov    %eax,-0x50(%rbp)
call   1030 <clock@plt>
mov    -0x50(%rbp),%edx
cvtsi2sd %rax,%xmm0
mov    0x2db6(%rip),%rax
mov    (%rax),%ecx
mov    $0x3e8,%eax
idiv   %ecx
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x3c(%rbp),%esi
movsd  -0x30(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
mov    -0x10(%rbp),%rdx
lea    0xdeb(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
movsd  -0x30(%rbp),%xmm0
movaps 0xd6c(%rip),%xmm2
movq   -0x10(%rbp),%xmm1
punpckldq %xmm2,%xmm1
movapd 0xd6b(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    133f <read_data_c+0x1df>
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
mov    $0x7e,%esi
call   1070 <write_data@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
cvtsi2sd %rax,%xmm0
mov    $0x3e8,%eax
mov    0x2ce6(%rip),%rcx
cltd
idivl  (%rcx)
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    133a <read_data_c+0x1da>
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2ca5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    133f <read_data_c+0x1df>
jmp    11fb <read_data_c+0x9b>
movsbl -0x49(%rbp),%esi
mov    -0x44(%rbp),%edx
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x49(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_data_c>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edx,%ebx
mov    %rsi,%r15
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <clock@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <clock@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2e4b(%rip),%r13
mov    0x0(%r13),%ecx
mov    $0x3e8,%eax
xor    %edx,%edx
idiv   %ecx
cvtsi2sd %eax,%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movb   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
lea    0xe55(%rip),%rdi
mov    %ebx,0x14(%rsp)
mov    %ebx,%esi
mov    %r15,%rdx
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
movq   %r15,%xmm0
punpckldq 0xe12(%rip),%xmm0
subpd  0xe1a(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,0x20(%rsp)
xor    %ebx,%ebx
xor    %r14d,%r14d
jmp    121c <read_data_c+0xbc>
nop
add    $0x1,%ebx
test   %r12d,%r12d
jg     12df <read_data_c+0x17f>
mov    %ebp,%edi
mov    %rsp,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   1040 <clock@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    $0x3e8,%eax
xor    %edx,%edx
idivl  0x0(%r13)
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
mulsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
movsd  0x18(%rsp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xdf5(%rip),%rdi
mov    %r14d,%esi
mov    %r15,%rdx
mov    $0x3,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
ucomisd 0x20(%rsp),%xmm0
jbe    1210 <read_data_c+0xb0>
lea    0xe27(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    $0x7e,%esi
call   1070 <write_data@plt>
add    $0x1,%r14d
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rcx
mov    $0x3e8,%eax
xor    %edx,%edx
idivl  0x0(%r13)
cmp    0x14(%rsp),%r14d
je     1308 <read_data_c+0x1a8>
xorps  %xmm0,%xmm0
cvtsi2sd %rcx,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
jmp    1210 <read_data_c+0xb0>
mov    (%rsp),%al
movsbl %al,%ebp
lea    0xdb1(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdde(%rip),%rdi
call   1030 <puts@plt>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@CLOCKS_PER_SEC = global i32 0
@.str = [67 x i8] c"n wait_states %d, wait_time = %d, clock = %f, clocks_per_sec = %d\0A\00"
@.str.1 = [58 x i8] c"\0Await_=%d, time %u\0A start= %f, end = %f, wait_time = %d\0A \00"
@.str.2 = [55 x i8] c"Error: Exceeded wait time \0ASending null character '~'\0A\00"
@.str.3 = [36 x i8] c"Error: Esceeded wait states.. Exit\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.4 = [26 x i8] c"response = %x, cont = %d\0A\00"
define signext i8 @read_data_c(i32 %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [5 x i8]
store i32 %0, i32* %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%15 = call i64 (...) @clock()
%16 = sitofp i64 %15 to double
store double %16, double* %10
%17 = call i64 (...) @clock()
%18 = sitofp i64 %17 to double
%19 = load i32, i32* @CLOCKS_PER_SEC
%20 = sdiv i32 1000, %19
%21 = sitofp i32 %20 to double
%22 = fmul double %18, %21
store double %22, double* %7
store double 0.000000e+00, double* %9
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
%23 = bitcast [5 x i8]* %14 to i8*
%24 = load i32, i32* %6
%25 = load i64, i64* %5
%26 = load double, double* %10
%27 = load i32, i32* @CLOCKS_PER_SEC
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %24, i64 %25, double %26, i32 %27)
br label %29
29: ; preds = %77, %3
%30 = load i32, i32* %12
%31 = icmp slt i32 %30, 1
br i1 %31, label %32, label %78
32: ; preds = %29
%33 = load i32, i32* %4
%34 = getelementptr inbounds [5 x i8], [5 x i8]* %14, i64 0, i64 0
%35 = call i32 @read(i32 %33, i8* %34, i32 1)
store i32 %35, i32* %12
%36 = call i64 (...) @clock()
%37 = sitofp i64 %36 to double
%38 = load i32, i32* @CLOCKS_PER_SEC
%39 = sdiv i32 1000, %38
%40 = sitofp i32 %39 to double
%41 = fmul double %37, %40
store double %41, double* %8
%42 = load double, double* %8
%43 = load double, double* %7
%44 = fsub double %42, %43
store double %44, double* %9
%45 = load i32, i32* %11
%46 = load double, double* %9
%47 = load double, double* %7
%48 = load double, double* %8
%49 = load i64, i64* %5
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %45, double %46, double %47, double %48, i64 %49)
%51 = load i32, i32* %13
%52 = add nsw i32 %51, 1
store i32 %52, i32* %13
%53 = load double, double* %9
%54 = load i64, i64* %5
%55 = uitofp i64 %54 to double
%56 = fcmp ogt double %53, %55
br i1 %56, label %57, label %77
57: ; preds = %32
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
%59 = load i32, i32* %4
%60 = call i32 @write_data(i32 %59, i32 126)
%61 = load i32, i32* %11
%62 = add nsw i32 %61, 1
store i32 %62, i32* %11
store double 0.000000e+00, double* %9
%63 = call i64 (...) @clock()
%64 = sitofp i64 %63 to double
%65 = load i32, i32* @CLOCKS_PER_SEC
%66 = sdiv i32 1000, %65
%67 = sitofp i32 %66 to double
%68 = fmul double %64, %67
store double %68, double* %7
%69 = load i32, i32* %11
%70 = load i32, i32* %6
%71 = icmp eq i32 %69, %70
br i1 %71, label %72, label %76
72: ; preds = %57
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%74 = load i32, i32* @EXIT_SUCCESS
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %57
br label %77
77: ; preds = %76, %32
br label %29
78: ; preds = %29
%79 = getelementptr inbounds [5 x i8], [5 x i8]* %14, i64 0, i64 0
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = load i32, i32* %13
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %81, i32 %82)
%84 = getelementptr inbounds [5 x i8], [5 x i8]* %14, i64 0, i64 0
%85 = load i8, i8* %84
ret i8 %85
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global i32 0
@.str = [67 x i8] c"n wait_states %d, wait_time = %d, clock = %f, clocks_per_sec = %d\0A\00"
@.str.1 = [58 x i8] c"\0Await_=%d, time %u\0A start= %f, end = %f, wait_time = %d\0A \00"
@EXIT_SUCCESS = global i32 0
@.str.4 = [26 x i8] c"response = %x, cont = %d\0A\00"
@str = [54 x i8] c"Error: Exceeded wait time \0ASending null character '~'\00"
@str.5 = [35 x i8] c"Error: Esceeded wait states.. Exit\00"
define signext i8 @read_data_c(i32 %0, i64 %1, i32 %2) {
%4 = alloca [5 x i8]
%5 = tail call i64 (...) @clock()
%6 = sitofp i64 %5 to double
%7 = tail call i64 (...) @clock()
%8 = sitofp i64 %7 to double
%9 = load i32, i32* @CLOCKS_PER_SEC
%10 = sdiv i32 1000, %9
%11 = sitofp i32 %10 to double
%12 = fmul double %8, %11
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i32 %2, i64 %1, double %6, i32 %9)
%15 = uitofp i64 %1 to double
br label %16
16: ; preds = %3, %46
%17 = phi i32 [ 0, %3 ], [ %29, %46 ]
%18 = phi i32 [ 0, %3 ], [ %48, %46 ]
%19 = phi double [ %12, %3 ], [ %47, %46 ]
%20 = call i32 @read(i32 %0, i8* %13, i32 1)
%21 = tail call i64 (...) @clock()
%22 = sitofp i64 %21 to double
%23 = load i32, i32* @CLOCKS_PER_SEC
%24 = sdiv i32 1000, %23
%25 = sitofp i32 %24 to double
%26 = fmul double %22, %25
%27 = fsub double %26, %19
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %18, double %27, double %19, double %26, i64 %1)
%29 = add nuw nsw i32 %17, 1
%30 = fcmp ogt double %27, %15
br i1 %30, label %31, label %46
31: ; preds = %16
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str, i64 0, i64 0))
%33 = tail call i32 @write_data(i32 %0, i32 126)
%34 = add nsw i32 %18, 1
%35 = tail call i64 (...) @clock()
%36 = sitofp i64 %35 to double
%37 = load i32, i32* @CLOCKS_PER_SEC
%38 = sdiv i32 1000, %37
%39 = sitofp i32 %38 to double
%40 = fmul double %36, %39
%41 = icmp eq i32 %34, %2
br i1 %41, label %42, label %46
42: ; preds = %31
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.5, i64 0, i64 0))
%44 = load i32, i32* @EXIT_SUCCESS
%45 = tail call i32 @exit(i32 %44)
unreachable
46: ; preds = %31, %16
%47 = phi double [ %40, %31 ], [ %19, %16 ]
%48 = phi i32 [ %34, %31 ], [ %18, %16 ]
%49 = icmp slt i32 %20, 1
br i1 %49, label %16, label %50
50: ; preds = %46
%51 = load i8, i8* %13
%52 = sext i8 %51 to i32
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %52, i32 %29)
ret i8 %51
}