#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*/ uint64_t;

/* Variables and functions */
int /*<<< orphan*/ BLKDISCARD;
int EINVAL;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int discard(const char *path, uint64_t sector_b, uint64_t sector_e) {
  int r, fd;
  uint64_t payload[2];
  fd = open(path, O_RDWR);
  if (fd < 0) {
    fprintf(stderr, "couldn't open %s", path);
    return -EINVAL;
  }
  payload[0] = sector_b;
  payload[1] = sector_e;
  r = ioctl(fd, BLKDISCARD, payload);
  close(fd);
  return r;
}


x86 assembly (clang, -O0):
<discard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    119d <discard+0x5d>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7b(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
mov    0x2e35(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11cf <discard+0x8f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<discard>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     1189 <discard+0x49>
mov    %eax,%ebx
mov    %ebp,(%rsp)
mov    %r15d,0x4(%rsp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
jmp    11ac <discard+0x6c>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    0x2e20(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"couldn't open %s\00"
@EINVAL = global i32 0
@BLKDISCARD = global i32 0
define i32 @discard(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [2 x i32]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i8*, i8** %5
%12 = load i32, i32* @O_RDWR
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %5
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EINVAL
%21 = sub nsw i32 0, %20
store i32 %21, i32* %4
br label %34
22: ; preds = %3
%23 = load i32, i32* %6
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
store i32 %23, i32* %24
%25 = load i32, i32* %7
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
store i32 %25, i32* %26
%27 = load i32, i32* %9
%28 = load i32, i32* @BLKDISCARD
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%30 = call i32 @ioctl(i32 %27, i32 %28, i32* %29)
store i32 %30, i32* %8
%31 = load i32, i32* %9
%32 = call i32 @close(i32 %31)
%33 = load i32, i32* %8
store i32 %33, i32* %4
br label %34
34: ; preds = %22, %16
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"couldn't open %s\00"
@EINVAL = global i32 0
@BLKDISCARD = global i32 0
define i32 @discard(i8* %0, i32 %1, i32 %2) {
%4 = alloca [2 x i32]
%5 = bitcast [2 x i32]* %4 to i8*
%6 = load i32, i32* @O_RDWR
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = load i32, i32* @EINVAL
%13 = sub nsw i32 0, %12
br label %20
14: ; preds = %3
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
store i32 %1, i32* %15
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
store i32 %2, i32* %16
%17 = load i32, i32* @BLKDISCARD
%18 = call i32 @ioctl(i32 %7, i32 %17, i32* %15)
%19 = call i32 @close(i32 %7)
br label %20
20: ; preds = %14, %9
%21 = phi i32 [ %13, %9 ], [ %18, %14 ]
ret i32 %21
}