#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int Checkwrite(char const *, struct stat *, int, int, int);
int /*<<< orphan*/ Clear_timeout();
scalar_t__ Set_timeout();
int /*<<< orphan*/ Set_timeout_alarm(int);
int Checkwrite_timeout(int timeout, const char *file, struct stat *statb,
                       int rw, int create, int nodelay) {
  int fd;
  if (Set_timeout()) {
    Set_timeout_alarm(timeout);
    fd = Checkwrite(file, statb, rw, create, nodelay);
  } else {
    fd = -1;
  }
  Clear_timeout();
  return (fd);
}


x86 assembly (clang, -O0):
<Checkwrite_timeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    $0x0,%al
call   1040 <Set_timeout@plt>
cmp    $0x0,%rax
je     1196 <Checkwrite_timeout+0x56>
mov    -0x4(%rbp),%edi
call   1050 <Set_timeout_alarm@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
call   1060 <Checkwrite@plt>
mov    %eax,-0x28(%rbp)
jmp    119d <Checkwrite_timeout+0x5d>
movl   $0xffffffff,-0x28(%rbp)
mov    $0x0,%al
call   1030 <Clear_timeout@plt>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Checkwrite_timeout>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r14d
mov    %r8d,%r15d
mov    %ecx,%r12d
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <Set_timeout@plt>
test   %rax,%rax
je     1187 <Checkwrite_timeout+0x47>
mov    %ebp,%edi
call   1050 <Set_timeout_alarm@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1060 <Checkwrite@plt>
mov    %eax,%ebx
jmp    118c <Checkwrite_timeout+0x4c>
mov    $0xffffffff,%ebx
xor    %eax,%eax
call   1030 <Clear_timeout@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @Checkwrite_timeout(i32 %0, i8* %1, %struct.stat* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca %struct.stat*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %7
store i8* %1, i8** %8
store %struct.stat* %2, %struct.stat** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%14 = call i64 (...) @Set_timeout()
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %6
%17 = load i32, i32* %7
%18 = call i32 @Set_timeout_alarm(i32 %17)
%19 = load i8*, i8** %8
%20 = load %struct.stat*, %struct.stat** %9
%21 = load i32, i32* %10
%22 = load i32, i32* %11
%23 = load i32, i32* %12
%24 = call i32 @Checkwrite(i8* %19, %struct.stat* %20, i32 %21, i32 %22, i32 %23)
store i32 %24, i32* %13
br label %26
25: ; preds = %6
store i32 -1, i32* %13
br label %26
26: ; preds = %25, %16
%27 = call i32 (...) @Clear_timeout()
%28 = load i32, i32* %13
ret i32 %28
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @Checkwrite_timeout(i32 %0, i8* %1, %struct.stat* %2, i32 %3, i32 %4, i32 %5) {
%7 = tail call i64 (...) @Set_timeout()
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i32 @Set_timeout_alarm(i32 %0)
%11 = tail call i32 @Checkwrite(i8* %1, %struct.stat* %2, i32 %3, i32 %4, i32 %5)
br label %12
12: ; preds = %6, %9
%13 = phi i32 [ %11, %9 ], [ -1, %6 ]
%14 = tail call i32 (...) @Clear_timeout()
ret i32 %13
}