#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;
typedef int /*<<< orphan*/ uint16_t;
struct p9_handle {
  int dummy;
};
struct p9_fid {
  int dummy;
};
typedef scalar_t__ ssize_t;

/* Variables and functions */
scalar_t__ p9p_write_send(struct p9_handle *, struct p9_fid *, char *, size_t,
                          int /*<<< orphan*/, int /*<<< orphan*/ *);
scalar_t__ p9p_write_wait(struct p9_handle *, int /*<<< orphan*/);
ssize_t p9p_write(struct p9_handle *p9_handle, struct p9_fid *fid, char *buf,
                  size_t count, uint64_t offset) {
  ssize_t rc;
  uint16_t tag;
  rc = p9p_write_send(p9_handle, fid, buf, count, offset, &tag);
  if (rc)
    return rc;
  return p9p_write_wait(p9_handle, tag);
}


x86 assembly (clang, -O0):
<p9p_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
lea    -0x3c(%rbp),%r9
call   1040 <p9p_write_send@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1175 <p9p_write+0x55>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1185 <p9p_write+0x65>
mov    -0x10(%rbp),%rdi
mov    -0x3c(%rbp),%esi
call   1030 <p9p_write_wait@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p9p_write>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xc(%rsp),%r9
call   1040 <p9p_write_send@plt>
test   %rax,%rax
jne    1143 <p9p_write+0x23>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1030 <p9p_write_wait@plt>
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.p9_handle = type { i32 }
%struct.p9_fid = type { i32 }
define i64 @p9p_write(%struct.p9_handle* %0, %struct.p9_fid* %1, i8* %2, i64 %3, i32 %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = call i64 @p9p_write_send(%struct.p9_handle* %0, %struct.p9_fid* %1, i8* %2, i64 %3, i32 %4, i32* %6)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i32, i32* %6
%12 = call i64 @p9p_write_wait(%struct.p9_handle* %0, i32 %11)
br label %13
13: ; preds = %5, %10
%14 = phi i64 [ %12, %10 ], [ %8, %5 ]
ret i64 %14
}