#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 /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int, char *, int);
void emitload(int outfd, int reg, unsigned value) {
  char buf[8] = {
      0x3c,        0x04 + reg, value >> 24,
      value >> 16, 0x34,       0x84 + reg + (reg << 5),
      value >> 8,  value,
  };
  if (write(outfd, buf, sizeof(buf)) != sizeof(buf)) {
    fprintf(stderr, "write: %s\n", strerror(errno));
    exit(1);
  }
}


x86 assembly (clang, -O0):
<emitload>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movb   $0x3c,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x4,%eax
mov    %al,-0x13(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x18,%eax
mov    %al,-0x12(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x10,%eax
mov    %al,-0x11(%rbp)
movb   $0x34,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x84,%eax
mov    -0x8(%rbp),%ecx
shl    $0x5,%ecx
add    %ecx,%eax
mov    %al,-0xf(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x8,%eax
mov    %al,-0xe(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,-0xd(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
cltq
cmp    $0x8,%rax
je     11e9 <emitload+0xa9>
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe26(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emitload>:
push   %rbx
sub    $0x10,%rsp
movb   $0x3c,0x8(%rsp)
lea    0x4(%rsi),%eax
mov    %al,0x9(%rsp)
mov    %edx,%eax
shr    $0x18,%eax
mov    %al,0xa(%rsp)
mov    %edx,%eax
shr    $0x10,%eax
mov    %al,0xb(%rsp)
movb   $0x34,0xc(%rsp)
mov    %esi,%eax
shl    $0x5,%eax
add    %esi,%eax
add    $0x84,%al
mov    %al,0xd(%rsp)
mov    %dh,0xe(%rsp)
mov    %dl,0xf(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
cmp    $0x8,%eax
jne    1197 <emitload+0x57>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e42(%rip),%rax
mov    (%rax),%ebx
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe4b(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [11 x i8] c"write: %s\0A\00"
@errno = global i32 0
define void @emitload(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [8 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
store i8 60, i8* %8
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i32, i32* %5
%11 = add nsw i32 4, %10
%12 = trunc i32 %11 to i8
store i8 %12, i8* %9
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = load i32, i32* %6
%15 = lshr i32 %14, 24
%16 = trunc i32 %15 to i8
store i8 %16, i8* %13
%17 = getelementptr inbounds i8, i8* %13, i64 1
%18 = load i32, i32* %6
%19 = lshr i32 %18, 16
%20 = trunc i32 %19 to i8
store i8 %20, i8* %17
%21 = getelementptr inbounds i8, i8* %17, i64 1
store i8 52, i8* %21
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i32, i32* %5
%24 = add nsw i32 132, %23
%25 = load i32, i32* %5
%26 = shl i32 %25, 5
%27 = add nsw i32 %24, %26
%28 = trunc i32 %27 to i8
store i8 %28, i8* %22
%29 = getelementptr inbounds i8, i8* %22, i64 1
%30 = load i32, i32* %6
%31 = lshr i32 %30, 8
%32 = trunc i32 %31 to i8
store i8 %32, i8* %29
%33 = getelementptr inbounds i8, i8* %29, i64 1
%34 = load i32, i32* %6
%35 = trunc i32 %34 to i8
store i8 %35, i8* %33
%36 = load i32, i32* %4
%37 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%38 = call i32 @write(i32 %36, i8* %37, i32 8)
%39 = sext i32 %38 to i64
%40 = icmp ne i64 %39, 8
br i1 %40, label %41, label %47
41: ; preds = %3
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %3
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [11 x i8] c"write: %s\0A\00"
@errno = global i32 0
define void @emitload(i32 %0, i32 %1, i32 %2) {
%4 = alloca [8 x i8]
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
store i8 60, i8* %5
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 1
%7 = trunc i32 %1 to i8
%8 = add i8 %7, 4
store i8 %8, i8* %6
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 2
%10 = lshr i32 %2, 24
%11 = trunc i32 %10 to i8
store i8 %11, i8* %9
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 3
%13 = lshr i32 %2, 16
%14 = trunc i32 %13 to i8
store i8 %14, i8* %12
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 4
store i8 52, i8* %15
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 5
%17 = add nsw i32 %1, 132
%18 = shl i32 %1, 5
%19 = add nsw i32 %17, %18
%20 = trunc i32 %19 to i8
store i8 %20, i8* %16
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 6
%22 = lshr i32 %2, 8
%23 = trunc i32 %22 to i8
store i8 %23, i8* %21
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 7
%25 = trunc i32 %2 to i8
store i8 %25, i8* %24
%26 = call i32 @write(i32 %0, i8* %5, i32 8)
%27 = icmp eq i32 %26, 8
br i1 %27, label %34, label %28
28: ; preds = %3
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = tail call i8* @strerror(i32 %30)
%32 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %31)
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %3
ret void
}