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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned char);
int utf8_encode(int, unsigned char *);
void utf8_writebom(FILE *outptr) {
  int i, nc;
  unsigned char code[6];
  nc = utf8_encode(0xFEFF, code);
  for (i = 0; i < nc; ++i)
    fprintf(outptr, "%c", code[i]);
}


x86 assembly (clang, -O0):
<utf8_writebom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x16(%rbp),%rsi
mov    $0xfeff,%edi
call   1030 <utf8_encode@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1177 <utf8_writebom+0x57>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
lea    0xea1(%rip),%rsi
movzbl -0x16(%rbp,%rax,1),%edx
call   1040 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1144 <utf8_writebom+0x24>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_writebom>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0xa(%rsp),%rsi
mov    $0xfeff,%edi
call   1030 <utf8_encode@plt>
test   %eax,%eax
jle    1166 <utf8_writebom+0x46>
mov    %eax,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0xa(%rsp,%rbx,1),%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <utf8_writebom+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define void @utf8_writebom(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [6 x i8]
store i32* %0, i32** %2
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%7 = call i32 @utf8_encode(i32 65279, i8* %6)
store i32 %7, i32* %4
store i32 0, i32* %3
br label %8
8: ; preds = %19, %1
%9 = load i32, i32* %3
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = load i32*, i32** %2
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %17)
br label %19
19: ; preds = %12
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %8
22: ; preds = %8
ret void
}

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