#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 __u16;

/* Variables and functions */
void *hex_asc_lo(int);
int append_filetype_suffix(char *buf, __u16 filetype) {
  if (filetype == 0xffff)
    return 0;
  *buf++ = ',';
  *buf++ = hex_asc_lo(filetype >> 8);
  *buf++ = hex_asc_lo(filetype >> 4);
  *buf++ = hex_asc_lo(filetype >> 0);
  return 4;
}


x86 assembly (clang, -O0):
<append_filetype_suffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0xffff,-0x14(%rbp)
jne    1138 <append_filetype_suffix+0x28>
movl   $0x0,-0x4(%rbp)
jmp    11ab <append_filetype_suffix+0x9b>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x2c,(%rax)
mov    -0x14(%rbp),%edi
sar    $0x8,%edi
call   1030 <hex_asc_lo@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%edi
sar    $0x4,%edi
call   1030 <hex_asc_lo@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%edi
sar    $0x0,%edi
call   1030 <hex_asc_lo@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
movl   $0x4,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_filetype_suffix>:
xor    %eax,%eax
cmp    $0xffff,%esi
je     1154 <append_filetype_suffix+0x44>
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
movb   $0x2c,(%rdi)
mov    %esi,%edi
sar    $0x8,%edi
call   1030 <hex_asc_lo@plt>
mov    %al,0x1(%rbx)
mov    %ebp,%edi
sar    $0x4,%edi
call   1030 <hex_asc_lo@plt>
mov    %al,0x2(%rbx)
mov    %ebp,%edi
call   1030 <hex_asc_lo@plt>
mov    %al,0x3(%rbx)
mov    $0x4,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @append_filetype_suffix(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = icmp eq i32 %6, 65535
br i1 %7, label %8, label %9
8: ; preds = %2
store i32 0, i32* %3
br label %30
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %4
store i8 44, i8* %10
%12 = load i32, i32* %5
%13 = ashr i32 %12, 8
%14 = call i8* @hex_asc_lo(i32 %13)
%15 = ptrtoint i8* %14 to i8
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %4
store i8 %15, i8* %16
%18 = load i32, i32* %5
%19 = ashr i32 %18, 4
%20 = call i8* @hex_asc_lo(i32 %19)
%21 = ptrtoint i8* %20 to i8
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %4
store i8 %21, i8* %22
%24 = load i32, i32* %5
%25 = ashr i32 %24, 0
%26 = call i8* @hex_asc_lo(i32 %25)
%27 = ptrtoint i8* %26 to i8
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
store i8 %27, i8* %28
store i32 4, i32* %3
br label %30
30: ; preds = %9, %8
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
define i32 @append_filetype_suffix(i8* nocapture writeonly %0, i32 %1) {
%3 = icmp eq i32 %1, 65535
br i1 %3, label %19, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8, i8* %0, i64 1
store i8 44, i8* %0
%6 = ashr i32 %1, 8
%7 = tail call i8* @hex_asc_lo(i32 %6)
%8 = ptrtoint i8* %7 to i64
%9 = trunc i64 %8 to i8
%10 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %9, i8* %5
%11 = ashr i32 %1, 4
%12 = tail call i8* @hex_asc_lo(i32 %11)
%13 = ptrtoint i8* %12 to i64
%14 = trunc i64 %13 to i8
%15 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %14, i8* %10
%16 = tail call i8* @hex_asc_lo(i32 %1)
%17 = ptrtoint i8* %16 to i64
%18 = trunc i64 %17 to i8
store i8 %18, i8* %15
br label %19
19: ; preds = %2, %4
%20 = phi i32 [ 4, %4 ], [ 0, %2 ]
ret i32 %20
}