#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*/ *);
int fill_one_span_read(unsigned char *, unsigned char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int fill_cache_read(unsigned char *start_ptr, unsigned char *end_ptr,
                    char *resctrl_val) {
  int ret = 0;
  FILE *fp;
  while (1) {
    ret = fill_one_span_read(start_ptr, end_ptr);
    if (!strncmp(resctrl_val, "cat", sizeof("cat")))
      break;
  }
  fp = fopen("/dev/null", "w");
  if (!fp)
    perror("Unable to write to /dev/null");
  fprintf(fp, "Sum: %d ", ret);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<fill_cache_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <fill_one_span_read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe6a(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11ae <fill_cache_read+0x4e>
jmp    11b3 <fill_cache_read+0x53>
jmp    117b <fill_cache_read+0x1b>
lea    0xe5f(%rip),%rdi
lea    0xe43(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e1 <fill_cache_read+0x81>
lea    0xe2a(%rip),%rdi
call   1080 <perror@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe34(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_cache_read>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe87(%rip),%r13
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <fill_one_span_read@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1180 <fill_cache_read+0x20>
lea    0xe71(%rip),%rdi
lea    0xe55(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     11e1 <fill_cache_read+0x81>
lea    0xe60(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe1e(%rip),%rdi
call   1080 <perror@plt>
jmp    11bc <fill_cache_read+0x5c>

LLVM IR (-O0):
@.str = [4 x i8] c"cat\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [29 x i8] c"Unable to write to /dev/null\00"
@.str.4 = [9 x i8] c"Sum: %d \00"
define i32 @fill_cache_read(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %7
br label %9
9: ; preds = %3, %17
%10 = load i8*, i8** %4
%11 = load i8*, i8** %5
%12 = call i32 @fill_one_span_read(i8* %10, i8* %11)
store i32 %12, i32* %7
%13 = load i8*, i8** %6
%14 = call i32 @strncmp(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 4)
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %9
br label %18
17: ; preds = %9
br label %9
18: ; preds = %16
%19 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %19, i32** %8
%20 = load i32*, i32** %8
%21 = icmp ne i32* %20, null
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
%25 = load i32*, i32** %8
%26 = load i32, i32* %7
%27 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = load i32*, i32** %8
%29 = call i32 @fclose(i32* %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"cat\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [29 x i8] c"Unable to write to /dev/null\00"
@.str.4 = [9 x i8] c"Sum: %d \00"
define i32 @fill_cache_read(i8* %0, i8* %1, i8* %2) {
br label %4
4: ; preds = %4, %3
%5 = tail call i32 @fill_one_span_read(i8* %0, i8* %1)
%6 = tail call i32 @strncmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 4)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %4
8: ; preds = %4
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
%14 = tail call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %5)
%15 = tail call i32 @fclose(i32* %9)
ret i32 0
}