#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 EIO;
int /*<<< orphan*/ read_filename(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
scalar_t__ strstr(char *, char *);
int err_on_operation(int fd, const char *opname, size_t offset) {
  char filename[1024] = {0};
  char always_eio_trigger[1024] = {0};
  char far_eio_trigger[1024] = {0};
  read_filename(fd, filename, 1024);
  if (!strstr(filename, "/chunk_")) {
    return 0;
  }
  sprintf(always_eio_trigger, "%s_EIO", opname);
  sprintf(far_eio_trigger, "%s_far_EIO", opname);
  if (strstr(filename, always_eio_trigger)) {
    return EIO;
  } else if (strstr(filename, far_eio_trigger) && offset > 102400) {
    return EIO;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<err_on_operation>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
lea    -0xc20(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read_filename@plt>
lea    -0x420(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
jne    11cc <err_on_operation+0x8c>
movl   $0x0,-0x4(%rbp)
jmp    126b <err_on_operation+0x12b>
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe2a(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0xc20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe1a(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x420(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     1228 <err_on_operation+0xe8>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    126b <err_on_operation+0x12b>
lea    -0x420(%rbp),%rdi
lea    -0xc20(%rbp),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     1264 <err_on_operation+0x124>
cmpq   $0x19000,-0x18(%rbp)
jbe    1264 <err_on_operation+0x124>
mov    0x2d86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    126b <err_on_operation+0x12b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_on_operation>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xc00,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebx
lea    0x400(%rsp),%r12
xor    %ebp,%ebp
mov    $0x400,%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
lea    0x800(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x400,%edx
call   1060 <read_filename@plt>
lea    0xe57(%rip),%rsi
mov    %r12,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     1231 <err_on_operation+0xf1>
lea    0xe4b(%rip),%rsi
lea    0x800(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rdx
call   1040 <sprintf@plt>
lea    0xe38(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
call   1040 <sprintf@plt>
lea    0x400(%rsp),%rdi
mov    %rbx,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1202 <err_on_operation+0xc2>
mov    0x2de2(%rip),%rax
mov    (%rax),%ebp
jmp    1231 <err_on_operation+0xf1>
lea    0x400(%rsp),%rdi
mov    %rsp,%rsi
call   1050 <strstr@plt>
xor    %ebp,%ebp
mov    $0x0,%ecx
test   %rax,%rax
je     1227 <err_on_operation+0xe7>
mov    0x2dbb(%rip),%rax
mov    (%rax),%ecx
cmp    $0x19001,%r14
cmovae %ecx,%ebp
mov    %ebp,%eax
add    $0xc00,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"/chunk_\00"
@.str.1 = [7 x i8] c"%s_EIO\00"
@.str.2 = [11 x i8] c"%s_far_EIO\00"
@EIO = global i32 0
define i32 @err_on_operation(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
%10 = alloca [1024 x i8]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%11 = bitcast [1024 x i8]* %8 to i8*
%12 = bitcast [1024 x i8]* %9 to i8*
%13 = bitcast [1024 x i8]* %10 to i8*
%14 = load i32, i32* %5
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%16 = call i32 @read_filename(i32 %14, i8* %15, i32 1024)
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%18 = call i64 @strstr(i8* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %3
store i32 0, i32* %4
br label %45
21: ; preds = %3
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%23 = load i8*, i8** %6
%24 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%26 = load i8*, i8** %6
%27 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%30 = call i64 @strstr(i8* %28, i8* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = load i32, i32* @EIO
store i32 %33, i32* %4
br label %45
34: ; preds = %21
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%37 = call i64 @strstr(i8* %35, i8* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load i64, i64* %7
%41 = icmp ugt i64 %40, 102400
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = load i32, i32* @EIO
store i32 %43, i32* %4
br label %45
44: ; preds = %39, %34
store i32 0, i32* %4
br label %45
45: ; preds = %44, %42, %32, %20
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
@.str = [8 x i8] c"/chunk_\00"
@.str.1 = [7 x i8] c"%s_EIO\00"
@.str.2 = [11 x i8] c"%s_far_EIO\00"
@EIO = global i32 0
define i32 @err_on_operation(i32 %0, i8* %1, i64 %2) {
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%10 = call i32 @read_filename(i32 %0, i8* %7, i32 1024)
%11 = call i64 @strstr(i8* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %27, label %13
13: ; preds = %3
%14 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%15 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%16 = call i64 @strstr(i8* %7, i8* %8)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %13
%19 = load i32, i32* @EIO
br label %27
20: ; preds = %13
%21 = call i64 @strstr(i8* %7, i8* %9)
%22 = icmp ne i64 %21, 0
%23 = icmp ugt i64 %2, 102400
%24 = and i1 %23, %22
%25 = load i32, i32* @EIO
%26 = select i1 %24, i32 %25, i32 0
br label %27
27: ; preds = %20, %3, %18
%28 = phi i32 [ %19, %18 ], [ 0, %3 ], [ %26, %20 ]
ret i32 %28
}