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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
unsigned char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, unsigned int *);
int /*<<< orphan*/ printf(char *, unsigned char);
int rand();
int /*<<< orphan*/ srand(unsigned int);
unsigned int time(int /*<<< orphan*/ *);
int read() {
  FILE *data, *counter;
  unsigned int y, a;
  unsigned char b;
  y = time(NULL);
  srand(y);
  int i = 0, value = rand();
  counter = fopen("counter.txt", "r");
  data = fopen("data.txt", "r");
  fscanf(counter, "%d", &a);
  if (!a) {
    return 1;
  }
  while (i != (value % a + 1)) {
    b = fgetc(data);
    if (b == '#') {
      i++;
    }
  }
  while ((b = fgetc(data)) != '#') {
    printf("%c", b);
  }
  fclose(data);
  fclose(counter);
  return 0;
}


x86 assembly (clang, -O0):
<read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <srand@plt>
movl   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %eax,-0x2c(%rbp)
lea    0xe4c(%rip),%rdi
lea    0xe51(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe43(%rip),%rdi
lea    0xe3a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe31(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <fscanf@plt>
cmpl   $0x0,-0x20(%rbp)
jne    1205 <read+0x85>
movl   $0x1,-0x4(%rbp)
jmp    1298 <read+0x118>
jmp    120a <read+0x8a>
mov    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
xor    %edx,%edx
divl   -0x20(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%edx
cmp    %edx,%eax
je     124d <read+0xcd>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x21(%rbp)
movzbl -0x21(%rbp),%eax
cmp    $0x23,%eax
jne    1248 <read+0xc8>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    120a <read+0x8a>
jmp    1252 <read+0xd2>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x21(%rbp)
movzbl %al,%eax
cmp    $0x23,%eax
je     127f <read+0xff>
lea    0xda9(%rip),%rdi
movzbl -0x21(%rbp),%esi
call   1040 <printf@plt>
jmp    1252 <read+0xd2>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %eax,%r15d
lea    0xe58(%rip),%rdi
lea    0xe5d(%rip),%rbx
mov    %rbx,%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
lea    0xe4d(%rip),%rdi
mov    %rbx,%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
lea    0xe44(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
call   1050 <fscanf@plt>
cmpl   $0x0,0x4(%rsp)
je     125b <read+0xdb>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0x23,%al
sete   %cl
add    %ecx,%ebp
mov    %r15d,%eax
xor    %edx,%edx
divl   0x4(%rsp)
add    $0x1,%edx
cmp    %edx,%ebp
jne    11f0 <read+0x70>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    $0x23,%al
je     1247 <read+0xc7>
lea    0xdf6(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl %al,%esi
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    $0x23,%al
jne    1230 <read+0xb0>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1260 <read+0xe0>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"counter.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"data.txt\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [3 x i8] c"%c\00"
define i32 @read() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = call i32 @time(i32* null)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = call i32 @srand(i32 %10)
store i32 0, i32* %7
%12 = call i32 (...) @rand()
store i32 %12, i32* %8
%13 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %3
%14 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 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* %14, i32** %2
%15 = load i32*, i32** %3
%16 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %0
store i32 1, i32* %1
br label %52
20: ; preds = %0
br label %21
21: ; preds = %37, %20
%22 = load i32, i32* %7
%23 = load i32, i32* %8
%24 = load i32, i32* %5
%25 = urem i32 %23, %24
%26 = add i32 %25, 1
%27 = icmp ne i32 %22, %26
br i1 %27, label %28, label %38
28: ; preds = %21
%29 = load i32*, i32** %2
%30 = call zeroext i8 @fgetc(i32* %29)
store i8 %30, i8* %6
%31 = load i8, i8* %6
%32 = zext i8 %31 to i32
%33 = icmp eq i32 %32, 35
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %37
37: ; preds = %34, %28
br label %21
38: ; preds = %21
br label %39
39: ; preds = %44, %38
%40 = load i32*, i32** %2
%41 = call zeroext i8 @fgetc(i32* %40)
store i8 %41, i8* %6
%42 = zext i8 %41 to i32
%43 = icmp ne i32 %42, 35
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = load i8, i8* %6
%46 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %45)
br label %39
47: ; preds = %39
%48 = load i32*, i32** %2
%49 = call i32 @fclose(i32* %48)
%50 = load i32*, i32** %3
%51 = call i32 @fclose(i32* %50)
store i32 0, i32* %1
br label %52
52: ; preds = %47, %19
%53 = load i32, i32* %1
ret i32 %53
}

LLVM IR (-O2):
@.str = [12 x i8] c"counter.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"data.txt\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [3 x i8] c"%c\00"
define i32 @read() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = tail call i32 (...) @rand()
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
%10 = icmp eq i32 %9, 0
br i1 %10, label %32, label %14
11: ; preds = %14
%12 = call zeroext i8 @fgetc(i32* %7)
%13 = icmp eq i8 %12, 35
br i1 %13, label %29, label %24
14: ; preds = %0, %14
%15 = phi i32 [ %19, %14 ], [ 0, %0 ]
%16 = call zeroext i8 @fgetc(i32* %7)
%17 = icmp eq i8 %16, 35
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %15, %18
%20 = load i32, i32* %1
%21 = urem i32 %5, %20
%22 = add nuw i32 %21, 1
%23 = icmp eq i32 %19, %22
br i1 %23, label %11, label %14
24: ; preds = %11, %24
%25 = phi i8 [ %27, %24 ], [ %12, %11 ]
%26 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %25)
%27 = call zeroext i8 @fgetc(i32* %7)
%28 = icmp eq i8 %27, 35
br i1 %28, label %29, label %24
29: ; preds = %24, %11
%30 = call i32 @fclose(i32* %7)
%31 = call i32 @fclose(i32* %6)
br label %32
32: ; preds = %0, %29
%33 = phi i32 [ 0, %29 ], [ 1, %0 ]
ret i32 %33
}