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

/* Variables and functions */
int sshbuf_reserve(struct sshbuf *, int, int **);
int sshbuf_put_u64(struct sshbuf *buf, u_int64_t val) {
  u_char *p;
  int r;
  if ((r = sshbuf_reserve(buf, 8, &p)) < 0)
    return r;
  do {
    ((u_char *)(p))[0] = (((u_int64_t)(val)) >> 56) & 0xff;
    ((u_char *)(p))[1] = (((u_int64_t)(val)) >> 48) & 0xff;
    ((u_char *)(p))[2] = (((u_int64_t)(val)) >> 40) & 0xff;
    ((u_char *)(p))[3] = (((u_int64_t)(val)) >> 32) & 0xff;
    ((u_char *)(p))[4] = (((u_int64_t)(val)) >> 24) & 0xff;
    ((u_char *)(p))[5] = (((u_int64_t)(val)) >> 16) & 0xff;
    ((u_char *)(p))[6] = (((u_int64_t)(val)) >> 8) & 0xff;
    ((u_char *)(p))[7] = ((u_int64_t)(val)) & 0xff;
  } while (0);
  return 0;
}


x86 assembly (clang, -O0):
<sshbuf_put_u64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
lea    -0x20(%rbp),%rdx
call   1030 <sshbuf_reserve@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    1148 <sshbuf_put_u64+0x38>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1200 <sshbuf_put_u64+0xf0>
jmp    114d <sshbuf_put_u64+0x3d>
mov    -0x14(%rbp),%eax
mov    $0x38,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
mov    $0x30,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x14(%rbp),%eax
mov    $0x28,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x14(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
mov    %eax,%ecx
and    $0xff,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x14(%rbp),%ecx
sar    $0x18,%ecx
and    $0xff,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x14(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    -0x14(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x14(%rbp),%ecx
and    $0xff,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x1c(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sshbuf_put_u64>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
lea    0x8(%rsp),%rdx
mov    $0x8,%esi
call   1030 <sshbuf_reserve@plt>
test   %eax,%eax
js     1150 <sshbuf_put_u64+0x40>
mov    %ebx,%eax
shr    $0x18,%eax
mov    0x8(%rsp),%rcx
mov    %eax,0x10(%rcx)
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%eax
mov    %eax,0x14(%rcx)
movzbl %bh,%eax
mov    %eax,0x18(%rcx)
movzbl %bl,%eax
mov    %eax,0x1c(%rcx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_put_u64(%struct.sshbuf* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.sshbuf*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store %struct.sshbuf* %0, %struct.sshbuf** %4
store i32 %1, i32* %5
%8 = load %struct.sshbuf*, %struct.sshbuf** %4
%9 = call i32 @sshbuf_reserve(%struct.sshbuf* %8, i32 8, 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 %55
13: ; preds = %2
br label %14
14: ; preds = %13
%15 = load i32, i32* %5
%16 = ashr i32 %15, 56
%17 = and i32 %16, 255
%18 = load i32*, i32** %6
%19 = getelementptr inbounds i32, i32* %18, i64 0
store i32 %17, i32* %19
%20 = load i32, i32* %5
%21 = ashr i32 %20, 48
%22 = and i32 %21, 255
%23 = load i32*, i32** %6
%24 = getelementptr inbounds i32, i32* %23, i64 1
store i32 %22, i32* %24
%25 = load i32, i32* %5
%26 = ashr i32 %25, 40
%27 = and i32 %26, 255
%28 = load i32*, i32** %6
%29 = getelementptr inbounds i32, i32* %28, i64 2
store i32 %27, i32* %29
%30 = load i32, i32* %5
%31 = ashr i32 %30, 32
%32 = and i32 %31, 255
%33 = load i32*, i32** %6
%34 = getelementptr inbounds i32, i32* %33, i64 3
store i32 %32, i32* %34
%35 = load i32, i32* %5
%36 = ashr i32 %35, 24
%37 = and i32 %36, 255
%38 = load i32*, i32** %6
%39 = getelementptr inbounds i32, i32* %38, i64 4
store i32 %37, i32* %39
%40 = load i32, i32* %5
%41 = ashr i32 %40, 16
%42 = and i32 %41, 255
%43 = load i32*, i32** %6
%44 = getelementptr inbounds i32, i32* %43, i64 5
store i32 %42, i32* %44
%45 = load i32, i32* %5
%46 = ashr i32 %45, 8
%47 = and i32 %46, 255
%48 = load i32*, i32** %6
%49 = getelementptr inbounds i32, i32* %48, i64 6
store i32 %47, i32* %49
%50 = load i32, i32* %5
%51 = and i32 %50, 255
%52 = load i32*, i32** %6
%53 = getelementptr inbounds i32, i32* %52, i64 7
store i32 %51, i32* %53
br label %54
54: ; preds = %14
store i32 0, i32* %3
br label %55
55: ; preds = %54, %11
%56 = load i32, i32* %3
ret i32 %56
}

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