#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 char uint64_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ endianessConversion(char *, char *, int);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int htons(int);
void writeSequenceLength(uint64_t *length, FILE *f) {
  char tmpArray[8];
  if (htons(1) == 1) {
    fwrite(length, sizeof(uint64_t), 1, f);
  } else {
    endianessConversion((char *)length, tmpArray, sizeof(uint64_t));
    fwrite(tmpArray, sizeof(uint64_t), 1, f);
  }
}


x86 assembly (clang, -O0):
<writeSequenceLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%edi
call   1040 <htons@plt>
cmp    $0x1,%eax
jne    116c <writeSequenceLength+0x3c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1050 <fwrite@plt>
jmp    1192 <writeSequenceLength+0x62>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1030 <endianessConversion@plt>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1050 <fwrite@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeSequenceLength>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x1,%edi
call   1040 <htons@plt>
cmp    $0x1,%eax
jne    115b <writeSequenceLength+0x2b>
movsbl (%rbx),%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <fputc@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1030 <endianessConversion@plt>
movsbl (%rsp),%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @writeSequenceLength(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [8 x i8]
store i8* %0, i8** %3
store i32* %1, i32** %4
%6 = call i32 @htons(i32 1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = load i32*, i32** %4
%11 = call i32 @fwrite(i8* %9, i32 1, i32 1, i32* %10)
br label %19
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%15 = call i32 @endianessConversion(i8* %13, i8* %14, i32 1)
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%17 = load i32*, i32** %4
%18 = call i32 @fwrite(i8* %16, i32 1, i32 1, i32* %17)
br label %19
19: ; preds = %12, %8
ret void
}

LLVM IR (-O2):
define void @writeSequenceLength(i8* %0, i32* nocapture %1) {
%3 = alloca [8 x i8]
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @htons(i32 1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i8, i8* %0
%9 = sext i8 %8 to i32
%10 = tail call i32 @fputc(i32 %9, i32* %1)
br label %16
11: ; preds = %2
%12 = call i32 @endianessConversion(i8* %0, i8* %4, i32 1)
%13 = load i8, i8* %4
%14 = sext i8 %13 to i32
%15 = call i32 @fputc(i32 %14, i32* %1)
br label %16
16: ; preds = %11, %7
ret void
}