#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 u_int64_t;
typedef scalar_t__ u_int16_t;
typedef int u_char;
struct sshbuf {
  int dummy;
};

/* Variables and functions */
int sshbuf_reserve(struct sshbuf *, int, int **);
int sshbuf_put_u16(struct sshbuf *buf, u_int16_t val) {
  u_char *p;
  int r;
  if ((r = sshbuf_reserve(buf, 2, &p)) < 0)
    return r;
  do {
    ((u_char *)(p))[0] = (((u_int64_t)(val)) >> 8) & 0xff;
    ((u_char *)(p))[1] = ((u_int64_t)(val)) & 0xff;
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<sshbuf_put_u16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
lea    -0x20(%rbp),%rdx
call   1030 <sshbuf_reserve@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    1149 <sshbuf_put_u16+0x39>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117d <sshbuf_put_u16+0x6d>
jmp    114e <sshbuf_put_u16+0x3e>
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sshbuf_put_u16>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rdx
mov    $0x2,%esi
call   1030 <sshbuf_reserve@plt>
test   %eax,%eax
js     113d <sshbuf_put_u16+0x2d>
movzbl %bh,%eax
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx)
movzbl %bl,%eax
mov    %eax,0x4(%rcx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_put_u16(%struct.sshbuf* %0, i64 %1) {
%3 = alloca i32
%4 = alloca %struct.sshbuf*
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i32
store %struct.sshbuf* %0, %struct.sshbuf** %4
store i64 %1, i64* %5
%8 = load %struct.sshbuf*, %struct.sshbuf** %4
%9 = call i32 @sshbuf_reserve(%struct.sshbuf* %8, i32 2, i32** %6)
store i32 %9, i32* %7
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i32, i32* %7
store i32 %12, i32* %3
br label %27
13: ; preds = %2
br label %14
14: ; preds = %13
%15 = load i64, i64* %5
%16 = trunc i64 %15 to i32
%17 = ashr i32 %16, 8
%18 = and i32 %17, 255
%19 = load i32*, i32** %6
%20 = getelementptr inbounds i32, i32* %19, i64 0
store i32 %18, i32* %20
%21 = load i64, i64* %5
%22 = trunc i64 %21 to i32
%23 = and i32 %22, 255
%24 = load i32*, i32** %6
%25 = getelementptr inbounds i32, i32* %24, i64 1
store i32 %23, i32* %25
br label %26
26: ; preds = %14
store i32 0, i32* %3
br label %27
27: ; preds = %26, %11
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_put_u16(%struct.sshbuf* %0, i64 %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
%5 = call i32 @sshbuf_reserve(%struct.sshbuf* %0, i32 2, i32** %3)
%6 = icmp slt i32 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %2
%8 = trunc i64 %1 to i32
%9 = lshr i32 %8, 8
%10 = and i32 %9, 255
%11 = load i32*, i32** %3
store i32 %10, i32* %11
%12 = and i32 %8, 255
%13 = getelementptr inbounds i32, i32* %11, i64 1
store i32 %12, i32* %13
br label %14
14: ; preds = %2, %7
%15 = phi i32 [ 0, %7 ], [ %5, %2 ]
ret i32 %15
}