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

/* Variables and functions */
int write(int, unsigned char *, int);
int transmit_num_bytes(int fd, unsigned long num_bytes, unsigned char type) {
  unsigned int i;
  unsigned char num_bytes_array[5];
  for (i = 0; i < 4; i++)
    num_bytes_array[i] = (unsigned char)((num_bytes >> (i * 8)) & 0xff);
  num_bytes_array[i] = type;
  return write(fd, num_bytes_array, sizeof(num_bytes_array));
}


x86 assembly (clang, -O0):
<transmit_num_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jae    1161 <transmit_num_bytes+0x51>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x3,%ecx
mov    %ecx,%ecx
shr    %cl,%rax
and    $0xff,%rax
mov    %al,%cl
mov    -0x18(%rbp),%eax
mov    %cl,-0x1d(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112b <transmit_num_bytes+0x1b>
mov    -0x11(%rbp),%cl
mov    -0x18(%rbp),%eax
mov    %cl,-0x1d(%rbp,%rax,1)
mov    -0x4(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transmit_num_bytes>:
push   %rax
mov    %rsi,%rax
mov    %al,0x3(%rsp)
mov    %ah,0x4(%rsp)
mov    %rsi,%rcx
shr    $0x10,%rcx
mov    %cl,0x5(%rsp)
shr    $0x18,%rax
mov    %al,0x6(%rsp)
mov    %dl,0x7(%rsp)
lea    0x3(%rsp),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
pop    %rcx
ret

LLVM IR (-O0):
define i32 @transmit_num_bytes(i32 %0, i64 %1, i8 zeroext %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8
%7 = alloca i32
%8 = alloca [5 x i8]
store i32 %0, i32* %4
store i64 %1, i64* %5
store i8 %2, i8* %6
store i32 0, i32* %7
br label %9
9: ; preds = %23, %3
%10 = load i32, i32* %7
%11 = icmp ult i32 %10, 4
br i1 %11, label %12, label %26
12: ; preds = %9
%13 = load i64, i64* %5
%14 = load i32, i32* %7
%15 = mul i32 %14, 8
%16 = zext i32 %15 to i64
%17 = lshr i64 %13, %16
%18 = and i64 %17, 255
%19 = trunc i64 %18 to i8
%20 = load i32, i32* %7
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 %21
store i8 %19, i8* %22
br label %23
23: ; preds = %12
%24 = load i32, i32* %7
%25 = add i32 %24, 1
store i32 %25, i32* %7
br label %9
26: ; preds = %9
%27 = load i8, i8* %6
%28 = load i32, i32* %7
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 %29
store i8 %27, i8* %30
%31 = load i32, i32* %4
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%33 = call i32 @write(i32 %31, i8* %32, i32 5)
ret i32 %33
}

LLVM IR (-O2):
define i32 @transmit_num_bytes(i32 %0, i64 %1, i8 zeroext %2) {
%4 = alloca [5 x i8]
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%6 = trunc i64 %1 to i8
store i8 %6, i8* %5
%7 = lshr i64 %1, 8
%8 = trunc i64 %7 to i8
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 1
store i8 %8, i8* %9
%10 = lshr i64 %1, 16
%11 = trunc i64 %10 to i8
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 2
store i8 %11, i8* %12
%13 = lshr i64 %1, 24
%14 = trunc i64 %13 to i8
%15 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 3
store i8 %14, i8* %15
%16 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 4
store i8 %2, i8* %16
%17 = call i32 @write(i32 %0, i8* %5, i32 5)
ret i32 %17
}