#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 scalar_t__ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ write(int, scalar_t__ *, int);
void write_four_char(int fd, char *val) {
  uint8_t bytes[4];
  bytes[0] = (uint8_t)(val[3] & 0xff);
  bytes[1] = (uint8_t)(val[2] & 0xff);
  bytes[2] = (uint8_t)(val[1] & 0xff);
  bytes[3] = (uint8_t)(val[0] & 0xff);
  write(fd, bytes, 4);
}


x86 assembly (clang, -O0):
<write_four_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%eax
and    $0xff,%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
and    $0xff,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
and    $0xff,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0xff,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_four_char>:
sub    $0x28,%rsp
movzbl 0x3(%rsi),%eax
mov    %rax,(%rsp)
movzbl 0x2(%rsi),%eax
mov    %rax,0x8(%rsp)
movzbl 0x1(%rsi),%eax
mov    %rax,0x10(%rsp)
movzbl (%rsi),%eax
mov    %rax,0x18(%rsp)
mov    %rsp,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
define void @write_four_char(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [4 x i64]
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = getelementptr inbounds i8, i8* %6, i64 3
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = and i32 %9, 255
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [4 x i64], [4 x i64]* %5, i64 0, i64 0
store i64 %11, i64* %12
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 2
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = and i32 %16, 255
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [4 x i64], [4 x i64]* %5, i64 0, i64 1
store i64 %18, i64* %19
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = and i32 %23, 255
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [4 x i64], [4 x i64]* %5, i64 0, i64 2
store i64 %25, i64* %26
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = and i32 %30, 255
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [4 x i64], [4 x i64]* %5, i64 0, i64 3
store i64 %32, i64* %33
%34 = load i32, i32* %3
%35 = getelementptr inbounds [4 x i64], [4 x i64]* %5, i64 0, i64 0
%36 = call i32 @write(i32 %34, i64* %35, i32 4)
ret void
}

LLVM IR (-O2):
define void @write_four_char(i32 %0, i8* nocapture %1) {
%3 = alloca [4 x i64]
%4 = bitcast [4 x i64]* %3 to i8*
%5 = getelementptr inbounds i8, i8* %1, i64 3
%6 = load i8, i8* %5
%7 = zext i8 %6 to i64
%8 = getelementptr inbounds [4 x i64], [4 x i64]* %3, i64 0, i64 0
store i64 %7, i64* %8
%9 = getelementptr inbounds i8, i8* %1, i64 2
%10 = load i8, i8* %9
%11 = zext i8 %10 to i64
%12 = getelementptr inbounds [4 x i64], [4 x i64]* %3, i64 0, i64 1
store i64 %11, i64* %12
%13 = getelementptr inbounds i8, i8* %1, i64 1
%14 = load i8, i8* %13
%15 = zext i8 %14 to i64
%16 = getelementptr inbounds [4 x i64], [4 x i64]* %3, i64 0, i64 2
store i64 %15, i64* %16
%17 = load i8, i8* %1
%18 = zext i8 %17 to i64
%19 = getelementptr inbounds [4 x i64], [4 x i64]* %3, i64 0, i64 3
store i64 %18, i64* %19
%20 = call i32 @write(i32 %0, i64* %8, i32 4)
ret void
}