int send(dstkey, buf, nbytes)
int dstkey;
char *buf;
int nbytes;
{
  int sndsid, rcvsid, segid;
  char *addr;
  if (findinfo(dstkey, &sndsid, &rcvsid, &addr, &segid) != 0)
    return (-1);
  if (nbytes > 4096)
    nbytes = 4096;
  P(sndsid);
  memcpy(addr, buf, nbytes);
  V(rcvsid);
  return (0);
}


x86 assembly (clang, -O0):
<send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x20(%rbp),%r8
mov    $0x0,%al
call   1030 <findinfo@plt>
cmp    $0x0,%eax
je     1181 <send+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c1 <send+0x81>
cmpl   $0x1000,-0x14(%rbp)
jle    1195 <send+0x55>
movl   $0x1000,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    $0x0,%al
call   1040 <P@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x1c(%rbp),%edi
mov    $0x0,%al
call   1050 <V@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x1c(%rsp),%r8
xor    %eax,%eax
call   1030 <findinfo@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
jne    11a9 <send+0x69>
cmp    $0x1000,%ebp
mov    $0x1000,%ebx
cmovl  %ebp,%ebx
mov    0xc(%rsp),%edi
xor    %eax,%eax
call   1040 <P@plt>
mov    0x10(%rsp),%rdi
movslq %ebx,%rdx
mov    %r14,%rsi
call   1060 <memcpy@plt>
mov    0x8(%rsp),%edi
xor    %eax,%eax
call   1050 <V@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @send(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%12 = load i32, i32* %5
%13 = call i32 (i32, i32*, i32*, i8**, i32*, ...) bitcast (i32 (...)* @findinfo to i32 (i32, i32*, i32*, i8**, i32*, ...)*)(i32 %12, i32* %8, i32* %9, i8** %11, i32* %10)
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %29
16: ; preds = %3
%17 = load i32, i32* %7
%18 = icmp sgt i32 %17, 4096
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 4096, i32* %7
br label %20
20: ; preds = %19, %16
%21 = load i32, i32* %8
%22 = call i32 (i32, ...) bitcast (i32 (...)* @P to i32 (i32, ...)*)(i32 %21)
%23 = load i8*, i8** %11
%24 = load i8*, i8** %6
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = load i32, i32* %9
%28 = call i32 (i32, ...) bitcast (i32 (...)* @V to i32 (i32, ...)*)(i32 %27)
store i32 0, i32* %4
br label %29
29: ; preds = %20, %15
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @send(i32 %0, i8* nocapture %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = bitcast i8** %7 to i8*
%12 = call i32 (i32, i32*, i32*, i8**, i32*, ...) bitcast (i32 (...)* @findinfo to i32 (i32, i32*, i32*, i8**, i32*, ...)*)(i32 %0, i32* %4, i32* %5, i8** %7, i32* %6)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %3
%15 = icmp slt i32 %2, 4096
%16 = select i1 %15, i32 %2, i32 4096
%17 = load i32, i32* %4
%18 = call i32 (i32, ...) bitcast (i32 (...)* @P to i32 (i32, ...)*)(i32 %17)
%19 = load i8*, i8** %7
%20 = sext i32 %16 to i64
%21 = load i32, i32* %5
%22 = call i32 (i32, ...) bitcast (i32 (...)* @V to i32 (i32, ...)*)(i32 %21)
br label %23
23: ; preds = %3, %14
%24 = phi i32 [ 0, %14 ], [ -1, %3 ]
ret i32 %24
}