#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 scalar_t__ time_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ delete_newline(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *, char *);
scalar_t__ time(int /*<<< orphan*/ *);
void print_counter(const int timeout) {
  FILE *count_l, *count_r;
  char buff_l[256];
  char buff_r[256];
  time_t start = time(NULL);
  int elapsed_time = 0;
  while (elapsed_time < timeout) {
    if ((count_l = fopen("/dev/rtcounter_l0", "r")) != NULL &&
        (count_r = fopen("/dev/rtcounter_r0", "r")) != NULL) {
      while (fgets(buff_l, 256, count_l) != NULL) {
      }
      while (fgets(buff_r, 256, count_r) != NULL) {
      }
      delete_newline(buff_l);
      delete_newline(buff_r);
      printf("count_l:%s, count_r:%s\n", buff_l, buff_r);
    }
    fclose(count_l);
    fclose(count_r);
    elapsed_time = (int)(time(NULL) - start);
  }
}


x86 assembly (clang, -O0):
<print_counter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %edi,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %rax,-0x228(%rbp)
movl   $0x0,-0x22c(%rbp)
mov    -0x22c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    128a <print_counter+0x12a>
lea    0xe62(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     125d <print_counter+0xfd>
lea    0xe55(%rip),%rdi
lea    0xe4c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     125d <print_counter+0xfd>
jmp    11de <print_counter+0x7e>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1202 <print_counter+0xa2>
jmp    11de <print_counter+0x7e>
jmp    1207 <print_counter+0xa7>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     122b <print_counter+0xcb>
jmp    1207 <print_counter+0xa7>
lea    -0x120(%rbp),%rdi
call   1040 <delete_newline@plt>
lea    -0x220(%rbp),%rdi
call   1040 <delete_newline@plt>
lea    -0x120(%rbp),%rsi
lea    -0x220(%rbp),%rdx
lea    0xdce(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
sub    -0x228(%rbp),%rax
mov    %eax,-0x22c(%rbp)
jmp    1188 <print_counter+0x28>
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_counter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %edi,%r13d
xor    %edi,%edi
call   1070 <time@plt>
test   %r13d,%r13d
jle    125c <print_counter+0xfc>
mov    %rax,%rbx
lea    0x100(%rsp),%rbp
mov    %rsp,%r12
jmp    11c5 <print_counter+0x65>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %r14d,%r14d
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1070 <time@plt>
sub    %ebx,%eax
cmp    %r13d,%eax
jge    125c <print_counter+0xfc>
lea    0xe34(%rip),%rdi
lea    0xe3f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
je     11a3 <print_counter+0x43>
lea    0xe2d(%rip),%rdi
lea    0xe24(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11a0 <print_counter+0x40>
mov    %rax,%r14
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    1200 <print_counter+0xa0>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    1220 <print_counter+0xc0>
mov    %rbp,%rdi
call   1040 <delete_newline@plt>
mov    %r12,%rdi
call   1040 <delete_newline@plt>
lea    0xdda(%rip),%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1050 <printf@plt>
jmp    11a3 <print_counter+0x43>
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"/dev/rtcounter_l0\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"/dev/rtcounter_r0\00"
@.str.3 = [24 x i8] c"count_l:%s, count_r:%s\0A\00"
define void @print_counter(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %2
%9 = call i64 @time(i32* null)
store i64 %9, i64* %7
store i32 0, i32* %8
br label %10
10: ; preds = %42, %1
%11 = load i32, i32* %8
%12 = load i32, i32* %2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %51
14: ; preds = %10
%15 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %3
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %42
17: ; preds = %14
%18 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %4
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %42
20: ; preds = %17
br label %21
21: ; preds = %26, %20
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%23 = load i32*, i32** %3
%24 = call i32* @fgets(i8* %22, i32 256, i32* %23)
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %27
26: ; preds = %21
br label %21
27: ; preds = %21
br label %28
28: ; preds = %33, %27
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%30 = load i32*, i32** %4
%31 = call i32* @fgets(i8* %29, i32 256, i32* %30)
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %34
33: ; preds = %28
br label %28
34: ; preds = %28
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%36 = call i32 @delete_newline(i8* %35)
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%38 = call i32 @delete_newline(i8* %37)
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%41 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %39, i8* %40)
br label %42
42: ; preds = %34, %17, %14
%43 = load i32*, i32** %3
%44 = call i32 @fclose(i32* %43)
%45 = load i32*, i32** %4
%46 = call i32 @fclose(i32* %45)
%47 = call i64 @time(i32* null)
%48 = load i64, i64* %7
%49 = sub nsw i64 %47, %48
%50 = trunc i64 %49 to i32
store i32 %50, i32* %8
br label %10
51: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"/dev/rtcounter_l0\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"/dev/rtcounter_r0\00"
@.str.3 = [24 x i8] c"count_l:%s, count_r:%s\0A\00"
define void @print_counter(i32 %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = tail call i64 @time(i32* null)
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %33
8: ; preds = %1, %25
%9 = phi i32* [ %26, %25 ], [ undef, %1 ]
%10 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %25, label %12
12: ; preds = %8
%13 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %25, label %15
15: ; preds = %12, %15
%16 = call i32* @fgets(i8* %4, i32 256, i32* %10)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %15
18: ; preds = %15, %18
%19 = call i32* @fgets(i8* %5, i32 256, i32* %13)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %18
21: ; preds = %18
%22 = call i32 @delete_newline(i8* %4)
%23 = call i32 @delete_newline(i8* %5)
%24 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %4, i8* %5)
br label %25
25: ; preds = %21, %12, %8
%26 = phi i32* [ %13, %21 ], [ null, %12 ], [ %9, %8 ]
%27 = call i32 @fclose(i32* %10)
%28 = call i32 @fclose(i32* %26)
%29 = call i64 @time(i32* null)
%30 = sub nsw i64 %29, %6
%31 = trunc i64 %30 to i32
%32 = icmp slt i32 %31, %0
br i1 %32, label %8, label %33
33: ; preds = %25, %1
ret void
}