#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 */
scalar_t__ EFBIG;
int EINVAL;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int ftruncate64(int, unsigned long long);
int /*<<< orphan*/ stderr;
int test_for_efbig(int fd, unsigned long long max_off) {
  int ret;
  max_off++;
  ret = ftruncate64(fd, max_off);
  if (ret == 0 || (ret == -1 && errno != EFBIG)) {
    fprintf(stderr, "Test to ftruncate past max_off failed\n");
    return EINVAL;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_for_efbig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <ftruncate64@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1178 <test_for_efbig+0x58>
cmpl   $0xffffffff,-0x14(%rbp)
jne    119e <test_for_efbig+0x7e>
mov    0x2e6b(%rip),%rax
mov    (%rax),%rax
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%rax
je     119e <test_for_efbig+0x7e>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11a5 <test_for_efbig+0x85>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_for_efbig>:
push   %rax
add    $0x1,%rsi
call   1040 <ftruncate64@plt>
test   %eax,%eax
je     114d <test_for_efbig+0x2d>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    116b <test_for_efbig+0x4b>
mov    0x2e92(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2ea0(%rip),%rdx
cmp    (%rdx),%rcx
je     116b <test_for_efbig+0x4b>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret

LLVM IR (-O0):
@errno = global i64 0
@EFBIG = global i64 0
@stderr = global i32 0
@.str = [39 x i8] c"Test to ftruncate past max_off failed\0A\00"
@EINVAL = global i32 0
define i32 @test_for_efbig(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
store i32 %0, i32* %4
store i64 %1, i64* %5
%7 = load i64, i64* %5
%8 = add i64 %7, 1
store i64 %8, i64* %5
%9 = load i32, i32* %4
%10 = load i64, i64* %5
%11 = call i32 @ftruncate64(i32 %9, i64 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %2
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = load i64, i64* @errno
%19 = load i64, i64* @EFBIG
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %17, %2
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @EINVAL
store i32 %24, i32* %3
br label %26
25: ; preds = %17, %14
store i32 0, i32* %3
br label %26
26: ; preds = %25, %21
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@errno = global i64 0
@EFBIG = global i64 0
@stderr = global i32 0
@.str = [39 x i8] c"Test to ftruncate past max_off failed\0A\00"
@EINVAL = global i32 0
define i32 @test_for_efbig(i32 %0, i64 %1) {
%3 = add i64 %1, 1
%4 = tail call i32 @ftruncate64(i32 %0, i64 %3)
switch i32 %4, label %13 [
i32 0, label %9
i32 -1, label %5
]
5: ; preds = %2
%6 = load i64, i64* @errno
%7 = load i64, i64* @EFBIG
%8 = icmp eq i64 %6, %7
br i1 %8, label %13, label %9
9: ; preds = %2, %5
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EINVAL
br label %13
13: ; preds = %5, %2, %9
%14 = phi i32 [ %12, %9 ], [ 0, %2 ], [ 0, %5 ]
ret i32 %14
}