#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 x;
typedef int uint32_t;
struct buffer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ buffer_write8(struct buffer *, int);
void buffer_write_be32(struct buffer *b, uint32_t x) {
  buffer_write8(b, (x >> 24) & 0xff);
  buffer_write8(b, (x >> 16) & 0xff);
  buffer_write8(b, (x >> 8) & 0xff);
  buffer_write8(b, (x)&0xff);
}


x86 assembly (clang, -O0):
<buffer_write_be32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sar    $0x18,%esi
and    $0xff,%esi
call   1030 <buffer_write8@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sar    $0x10,%esi
and    $0xff,%esi
call   1030 <buffer_write8@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sar    $0x8,%esi
and    $0xff,%esi
call   1030 <buffer_write8@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
and    $0xff,%esi
call   1030 <buffer_write8@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buffer_write_be32>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
mov    %esi,%eax
shr    $0x18,%eax
mov    %eax,%esi
call   1030 <buffer_write8@plt>
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%esi
mov    %r14,%rdi
call   1030 <buffer_write8@plt>
movzbl %bh,%esi
mov    %r14,%rdi
call   1030 <buffer_write8@plt>
movzbl %bl,%esi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <buffer_write8@plt>

LLVM IR (-O0):
%struct.buffer = type { i32 }
define void @buffer_write_be32(%struct.buffer* %0, i32 %1) {
%3 = alloca %struct.buffer*
%4 = alloca i32
store %struct.buffer* %0, %struct.buffer** %3
store i32 %1, i32* %4
%5 = load %struct.buffer*, %struct.buffer** %3
%6 = load i32, i32* %4
%7 = ashr i32 %6, 24
%8 = and i32 %7, 255
%9 = call i32 @buffer_write8(%struct.buffer* %5, i32 %8)
%10 = load %struct.buffer*, %struct.buffer** %3
%11 = load i32, i32* %4
%12 = ashr i32 %11, 16
%13 = and i32 %12, 255
%14 = call i32 @buffer_write8(%struct.buffer* %10, i32 %13)
%15 = load %struct.buffer*, %struct.buffer** %3
%16 = load i32, i32* %4
%17 = ashr i32 %16, 8
%18 = and i32 %17, 255
%19 = call i32 @buffer_write8(%struct.buffer* %15, i32 %18)
%20 = load %struct.buffer*, %struct.buffer** %3
%21 = load i32, i32* %4
%22 = and i32 %21, 255
%23 = call i32 @buffer_write8(%struct.buffer* %20, i32 %22)
ret void
}

LLVM IR (-O2):
%struct.buffer = type { i32 }
define void @buffer_write_be32(%struct.buffer* %0, i32 %1) {
%3 = lshr i32 %1, 24
%4 = tail call i32 @buffer_write8(%struct.buffer* %0, i32 %3)
%5 = lshr i32 %1, 16
%6 = and i32 %5, 255
%7 = tail call i32 @buffer_write8(%struct.buffer* %0, i32 %6)
%8 = lshr i32 %1, 8
%9 = and i32 %8, 255
%10 = tail call i32 @buffer_write8(%struct.buffer* %0, i32 %9)
%11 = and i32 %1, 255
%12 = tail call i32 @buffer_write8(%struct.buffer* %0, i32 %11)
ret void
}