#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 ssize_t;

/* Variables and functions */
int EIO;
int 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};
  ssize_t result = read_filename(fd, filename, 1024);
  if (result == -1) {
    return 0;
  }
  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    $0xc30,%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>
mov    %eax,-0xc24(%rbp)
cmpl   $0xffffffff,-0xc24(%rbp)
jne    11c2 <err_on_operation+0x82>
movl   $0x0,-0x4(%rbp)
jmp    128a <err_on_operation+0x14a>
lea    -0x420(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
jne    11eb <err_on_operation+0xab>
movl   $0x0,-0x4(%rbp)
jmp    128a <err_on_operation+0x14a>
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe0b(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0xc20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdfb(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x420(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     1247 <err_on_operation+0x107>
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    128a <err_on_operation+0x14a>
lea    -0x420(%rbp),%rdi
lea    -0xc20(%rbp),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     1283 <err_on_operation+0x143>
cmpq   $0x19000,-0x18(%rbp)
jbe    1283 <err_on_operation+0x143>
mov    0x2d67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    128a <err_on_operation+0x14a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc30,%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
mov    %rsp,%rbp
xor    %r12d,%r12d
mov    $0x400,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
lea    0x800(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1030 <memset@plt>
lea    0x400(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
call   1060 <read_filename@plt>
cmp    $0xffffffff,%eax
je     123e <err_on_operation+0xfe>
lea    0xe4d(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     123e <err_on_operation+0xfe>
lea    0xe41(%rip),%rsi
lea    0x800(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rdx
call   1040 <sprintf@plt>
lea    0xe2e(%rip),%rsi
lea    0x400(%rsp),%rdi
mov    %r15,%rdx
call   1040 <sprintf@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     120d <err_on_operation+0xcd>
mov    0x2dd8(%rip),%rax
mov    (%rax),%r12d
jmp    123e <err_on_operation+0xfe>
mov    %rsp,%rdi
lea    0x400(%rsp),%rsi
call   1050 <strstr@plt>
xor    %r12d,%r12d
mov    $0x0,%ecx
test   %rax,%rax
je     1233 <err_on_operation+0xf3>
mov    0x2daf(%rip),%rax
mov    (%rax),%ecx
cmp    $0x19001,%r14
cmovae %ecx,%r12d
mov    %r12d,%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]
%11 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%12 = bitcast [1024 x i8]* %8 to i8*
%13 = bitcast [1024 x i8]* %9 to i8*
%14 = bitcast [1024 x i8]* %10 to i8*
%15 = load i32, i32* %5
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%17 = call i32 @read_filename(i32 %15, i8* %16, i32 1024)
store i32 %17, i32* %11
%18 = load i32, i32* %11
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %3
store i32 0, i32* %4
br label %50
21: ; preds = %3
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%23 = call i64 @strstr(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %21
store i32 0, i32* %4
br label %50
26: ; preds = %21
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%28 = load i8*, i8** %6
%29 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%31 = load i8*, i8** %6
%32 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%35 = call i64 @strstr(i8* %33, i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %26
%38 = load i32, i32* @EIO
store i32 %38, i32* %4
br label %50
39: ; preds = %26
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%42 = call i64 @strstr(i8* %40, i8* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %39
%45 = load i64, i64* %7
%46 = icmp ugt i64 %45, 102400
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = load i32, i32* @EIO
store i32 %48, i32* %4
br label %50
49: ; preds = %44, %39
store i32 0, i32* %4
br label %50
50: ; preds = %49, %47, %37, %25, %20
%51 = load i32, i32* %4
ret i32 %51
}

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 = icmp eq i32 %10, -1
br i1 %11, label %29, label %12
12: ; preds = %3
%13 = call i64 @strstr(i8* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %29, label %15
15: ; preds = %12
%16 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%17 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%18 = call i64 @strstr(i8* %7, i8* %8)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %15
%21 = load i32, i32* @EIO
br label %29
22: ; preds = %15
%23 = call i64 @strstr(i8* %7, i8* %9)
%24 = icmp ne i64 %23, 0
%25 = icmp ugt i64 %2, 102400
%26 = and i1 %25, %24
%27 = load i32, i32* @EIO
%28 = select i1 %26, i32 %27, i32 0
br label %29
29: ; preds = %22, %12, %3, %20
%30 = phi i32 [ %21, %20 ], [ 0, %3 ], [ 0, %12 ], [ %28, %22 ]
ret i32 %30
}