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

/* Variables and functions */
char *intcat(char *, int, char *);
char *encode_istat(int stat) {
  static char buf[64];
  char *p;
  p = buf;
  *p++ = '<';
  if (stat) {
    p = intcat(p, stat & 0x8000, "CTR");
    p = intcat(p, stat & 0x4000, "OVR");
    p = intcat(p, stat & 0x2000, "ERR");
    p = intcat(p, stat & 0x1000, "WKUP");
    p = intcat(p, stat & 0x0800, "SUSP");
    p = intcat(p, stat & 0x0400, "RESET");
    p = intcat(p, stat & 0x0200, "SOF");
    p = intcat(p, stat & 0x0100, "ESOF");
    p = intcat(p, stat & 0x0010, "DIR");
    p--;
  } else {
    *p++ = '-';
  }
  *p++ = '>';
  *p = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<encode_istat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0x2f1e(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x3c,(%rax)
cmpl   $0x0,-0x4(%rbp)
je     1255 <encode_istat+0x145>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
and    $0x8000,%esi
lea    0xeaa(%rip),%rdx
call   1030 <intcat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
and    $0x4000,%esi
lea    0xe91(%rip),%rdx
call   1030 <intcat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
and    $0x2000,%esi
lea    0xe78(%rip),%rdx
call   1030 <intcat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
and    $0x1000,%esi
lea    0xe5f(%rip),%rdx
call   1030 <intcat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
and    $0x800,%esi
lea    0xe47(%rip),%rdx
call   1030 <intcat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
and    $0x400,%esi
lea    0xe2f(%rip),%rdx
call   1030 <intcat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
and    $0x200,%esi
lea    0xe19(%rip),%rdx
call   1030 <intcat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
and    $0x100,%esi
lea    0xdfb(%rip),%rdx
call   1030 <intcat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
and    $0x10,%esi
lea    0xde6(%rip),%rdx
call   1030 <intcat@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1267 <encode_istat+0x157>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x2d,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x3e,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2db9(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_istat>:
push   %rbx
movb   $0x3c,0x2f28(%rip)
test   %edi,%edi
je     11f8 <encode_istat+0xe8>
mov    %edi,%ebx
mov    %edi,%esi
and    $0x8000,%esi
lea    0x2f10(%rip),%rdi
lea    0xec8(%rip),%rdx
call   1030 <intcat@plt>
mov    %ebx,%esi
and    $0x4000,%esi
lea    0xeb8(%rip),%rdx
mov    %rax,%rdi
call   1030 <intcat@plt>
mov    %ebx,%esi
and    $0x2000,%esi
lea    0xea5(%rip),%rdx
mov    %rax,%rdi
call   1030 <intcat@plt>
mov    %ebx,%esi
and    $0x1000,%esi
lea    0xe92(%rip),%rdx
mov    %rax,%rdi
call   1030 <intcat@plt>
mov    %ebx,%esi
and    $0x800,%esi
lea    0xe80(%rip),%rdx
mov    %rax,%rdi
call   1030 <intcat@plt>
mov    %ebx,%esi
and    $0x400,%esi
lea    0xe6e(%rip),%rdx
mov    %rax,%rdi
call   1030 <intcat@plt>
mov    %ebx,%esi
and    $0x200,%esi
lea    0xe5e(%rip),%rdx
mov    %rax,%rdi
call   1030 <intcat@plt>
mov    %ebx,%esi
and    $0x100,%esi
lea    0xe46(%rip),%rdx
mov    %rax,%rdi
call   1030 <intcat@plt>
and    $0x10,%ebx
lea    0xe39(%rip),%rdx
mov    %rax,%rdi
mov    %ebx,%esi
call   1030 <intcat@plt>
add    $0xffffffffffffffff,%rax
jmp    1206 <encode_istat+0xf6>
movb   $0x2d,0x2e42(%rip)
lea    0x2e3c(%rip),%rax
movw   $0x3e,(%rax)
lea    0x2e2e(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
@encode_istat.buf = internal global [64 x i8] zeroinitializer
@.str = [4 x i8] c"CTR\00"
@.str.1 = [4 x i8] c"OVR\00"
@.str.2 = [4 x i8] c"ERR\00"
@.str.3 = [5 x i8] c"WKUP\00"
@.str.4 = [5 x i8] c"SUSP\00"
@.str.5 = [6 x i8] c"RESET\00"
@.str.6 = [4 x i8] c"SOF\00"
@.str.7 = [5 x i8] c"ESOF\00"
@.str.8 = [4 x i8] c"DIR\00"
define i8* @encode_istat(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
store i8* getelementptr inbounds ([64 x i8], [64 x i8]* @encode_istat.buf, i64 0, i64 0), i8** %3
%4 = load i8*, i8** %3
%5 = getelementptr inbounds i8, i8* %4, i32 1
store i8* %5, i8** %3
store i8 60, i8* %4
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %47
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i32, i32* %2
%11 = and i32 %10, 32768
%12 = call i8* @intcat(i8* %9, i32 %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = load i32, i32* %2
%15 = and i32 %14, 16384
%16 = call i8* @intcat(i8* %13, i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = load i32, i32* %2
%19 = and i32 %18, 8192
%20 = call i8* @intcat(i8* %17, i32 %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i8* %20, i8** %3
%21 = load i8*, i8** %3
%22 = load i32, i32* %2
%23 = and i32 %22, 4096
%24 = call i8* @intcat(i8* %21, i32 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %24, i8** %3
%25 = load i8*, i8** %3
%26 = load i32, i32* %2
%27 = and i32 %26, 2048
%28 = call i8* @intcat(i8* %25, i32 %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i8* %28, i8** %3
%29 = load i8*, i8** %3
%30 = load i32, i32* %2
%31 = and i32 %30, 1024
%32 = call i8* @intcat(i8* %29, i32 %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i8* %32, i8** %3
%33 = load i8*, i8** %3
%34 = load i32, i32* %2
%35 = and i32 %34, 512
%36 = call i8* @intcat(i8* %33, i32 %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
store i8* %36, i8** %3
%37 = load i8*, i8** %3
%38 = load i32, i32* %2
%39 = and i32 %38, 256
%40 = call i8* @intcat(i8* %37, i32 %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
store i8* %40, i8** %3
%41 = load i8*, i8** %3
%42 = load i32, i32* %2
%43 = and i32 %42, 16
%44 = call i8* @intcat(i8* %41, i32 %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
store i8* %44, i8** %3
%45 = load i8*, i8** %3
%46 = getelementptr inbounds i8, i8* %45, i32 -1
store i8* %46, i8** %3
br label %50
47: ; preds = %1
%48 = load i8*, i8** %3
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %3
store i8 45, i8* %48
br label %50
50: ; preds = %47, %8
%51 = load i8*, i8** %3
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %3
store i8 62, i8* %51
%53 = load i8*, i8** %3
store i8 0, i8* %53
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @encode_istat.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@encode_istat.buf = internal global [64 x i8] zeroinitializer
@.str = [4 x i8] c"CTR\00"
@.str.1 = [4 x i8] c"OVR\00"
@.str.2 = [4 x i8] c"ERR\00"
@.str.3 = [5 x i8] c"WKUP\00"
@.str.4 = [5 x i8] c"SUSP\00"
@.str.5 = [6 x i8] c"RESET\00"
@.str.6 = [4 x i8] c"SOF\00"
@.str.7 = [5 x i8] c"ESOF\00"
@.str.8 = [4 x i8] c"DIR\00"
define i8* @encode_istat(i32 %0) {
store i8 60, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @encode_istat.buf, i64 0, i64 0)
%2 = icmp eq i32 %0, 0
br i1 %2, label %23, label %3
3: ; preds = %1
%4 = and i32 %0, 32768
%5 = tail call i8* @intcat(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @encode_istat.buf, i64 0, i64 1), i32 %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = and i32 %0, 16384
%7 = tail call i8* @intcat(i8* %5, i32 %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%8 = and i32 %0, 8192
%9 = tail call i8* @intcat(i8* %7, i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%10 = and i32 %0, 4096
%11 = tail call i8* @intcat(i8* %9, i32 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%12 = and i32 %0, 2048
%13 = tail call i8* @intcat(i8* %11, i32 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%14 = and i32 %0, 1024
%15 = tail call i8* @intcat(i8* %13, i32 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%16 = and i32 %0, 512
%17 = tail call i8* @intcat(i8* %15, i32 %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%18 = and i32 %0, 256
%19 = tail call i8* @intcat(i8* %17, i32 %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%20 = and i32 %0, 16
%21 = tail call i8* @intcat(i8* %19, i32 %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%22 = getelementptr inbounds i8, i8* %21, i64 -1
br label %24
23: ; preds = %1
store i8 45, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @encode_istat.buf, i64 0, i64 1)
br label %24
24: ; preds = %23, %3
%25 = phi i8* [ %22, %3 ], [ getelementptr inbounds ([64 x i8], [64 x i8]* @encode_istat.buf, i64 0, i64 2), %23 ]
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8 62, i8* %25
store i8 0, i8* %26
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @encode_istat.buf, i64 0, i64 0)
}