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

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


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

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

LLVM IR (-O0):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_put_u32(%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 4, 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 %39
13: ; preds = %2
br label %14
14: ; preds = %13
%15 = load i64, i64* %5
%16 = trunc i64 %15 to i32
%17 = ashr i32 %16, 24
%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 = ashr i32 %22, 16
%24 = and i32 %23, 255
%25 = load i32*, i32** %6
%26 = getelementptr inbounds i32, i32* %25, i64 1
store i32 %24, i32* %26
%27 = load i64, i64* %5
%28 = trunc i64 %27 to i32
%29 = ashr i32 %28, 8
%30 = and i32 %29, 255
%31 = load i32*, i32** %6
%32 = getelementptr inbounds i32, i32* %31, i64 2
store i32 %30, i32* %32
%33 = load i64, i64* %5
%34 = trunc i64 %33 to i32
%35 = and i32 %34, 255
%36 = load i32*, i32** %6
%37 = getelementptr inbounds i32, i32* %36, i64 3
store i32 %35, i32* %37
br label %38
38: ; preds = %14
store i32 0, i32* %3
br label %39
39: ; preds = %38, %11
%40 = load i32, i32* %3
ret i32 %40
}

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