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

/* Variables and functions */
int sshbuf_consume(struct sshbuf *, int);
scalar_t__ *sshbuf_ptr(struct sshbuf *);
int sshbuf_get_u32(struct sshbuf *buf, u_int32_t *valp) {
  const u_char *p = sshbuf_ptr(buf);
  int r;
  if ((r = sshbuf_consume(buf, 4)) < 0)
    return r;
  if (valp != NULL)
    *valp = (((u_int32_t)(((const u_char *)(p))[0]) << 24) |
             ((u_int32_t)(((const u_char *)(p))[1]) << 16) |
             ((u_int32_t)(((const u_char *)(p))[2]) << 8) |
             (u_int32_t)(((const u_char *)(p))[3]));
  return 0;
}


x86 assembly (clang, -O0):
<sshbuf_get_u32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sshbuf_ptr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1030 <sshbuf_consume@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    1162 <sshbuf_get_u32+0x42>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11aa <sshbuf_get_u32+0x8a>
cmpq   $0x0,-0x18(%rbp)
je     11a3 <sshbuf_get_u32+0x83>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %eax,%ecx
shl    $0x18,%ecx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
shl    $0x10,%eax
or     %eax,%ecx
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rax
shl    $0x8,%eax
or     %eax,%ecx
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rax
or     %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sshbuf_get_u32>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <sshbuf_ptr@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    $0x4,%esi
call   1030 <sshbuf_consume@plt>
test   %eax,%eax
js     116a <sshbuf_get_u32+0x4a>
xor    %eax,%eax
test   %r14,%r14
je     116a <sshbuf_get_u32+0x4a>
mov    (%r15),%ecx
mov    0x8(%r15),%edx
shl    $0x18,%ecx
shl    $0x10,%edx
or     %ecx,%edx
mov    0x10(%r15),%ecx
shl    $0x8,%ecx
or     %edx,%ecx
or     0x18(%r15),%ecx
mov    %ecx,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_get_u32(%struct.sshbuf* %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.sshbuf*
%5 = alloca i32*
%6 = alloca i64*
%7 = alloca i32
store %struct.sshbuf* %0, %struct.sshbuf** %4
store i32* %1, i32** %5
%8 = load %struct.sshbuf*, %struct.sshbuf** %4
%9 = call i64* @sshbuf_ptr(%struct.sshbuf* %8)
store i64* %9, i64** %6
%10 = load %struct.sshbuf*, %struct.sshbuf** %4
%11 = call i32 @sshbuf_consume(%struct.sshbuf* %10, i32 4)
store i32 %11, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* %7
store i32 %14, i32* %3
br label %43
15: ; preds = %2
%16 = load i32*, i32** %5
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %42
18: ; preds = %15
%19 = load i64*, i64** %6
%20 = getelementptr inbounds i64, i64* %19, i64 0
%21 = load i64, i64* %20
%22 = trunc i64 %21 to i32
%23 = shl i32 %22, 24
%24 = load i64*, i64** %6
%25 = getelementptr inbounds i64, i64* %24, i64 1
%26 = load i64, i64* %25
%27 = trunc i64 %26 to i32
%28 = shl i32 %27, 16
%29 = or i32 %23, %28
%30 = load i64*, i64** %6
%31 = getelementptr inbounds i64, i64* %30, i64 2
%32 = load i64, i64* %31
%33 = trunc i64 %32 to i32
%34 = shl i32 %33, 8
%35 = or i32 %29, %34
%36 = load i64*, i64** %6
%37 = getelementptr inbounds i64, i64* %36, i64 3
%38 = load i64, i64* %37
%39 = trunc i64 %38 to i32
%40 = or i32 %35, %39
%41 = load i32*, i32** %5
store i32 %40, i32* %41
br label %42
42: ; preds = %18, %15
store i32 0, i32* %3
br label %43
43: ; preds = %42, %13
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_get_u32(%struct.sshbuf* %0, i32* writeonly %1) {
%3 = tail call i64* @sshbuf_ptr(%struct.sshbuf* %0)
%4 = tail call i32 @sshbuf_consume(%struct.sshbuf* %0, i32 4)
%5 = icmp slt i32 %4, 0
br i1 %5, label %26, label %6
6: ; preds = %2
%7 = icmp eq i32* %1, null
br i1 %7, label %26, label %8
8: ; preds = %6
%9 = load i64, i64* %3
%10 = trunc i64 %9 to i32
%11 = shl i32 %10, 24
%12 = getelementptr inbounds i64, i64* %3, i64 1
%13 = load i64, i64* %12
%14 = trunc i64 %13 to i32
%15 = shl i32 %14, 16
%16 = or i32 %15, %11
%17 = getelementptr inbounds i64, i64* %3, i64 2
%18 = load i64, i64* %17
%19 = trunc i64 %18 to i32
%20 = shl i32 %19, 8
%21 = or i32 %16, %20
%22 = getelementptr inbounds i64, i64* %3, i64 3
%23 = load i64, i64* %22
%24 = trunc i64 %23 to i32
%25 = or i32 %21, %24
store i32 %25, i32* %1
br label %26
26: ; preds = %6, %8, %2
%27 = phi i32 [ %4, %2 ], [ 0, %8 ], [ 0, %6 ]
ret i32 %27
}