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

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, long);
int /*<<< orphan*/ strcat(char *, char *);
char *sftos(long val, int flags) {
  static char buf[1024 + 14];
  static char c;
  char *ptr = (c) ? buf : buf + sizeof(buf) / 2;
  memset(buf, 0, sizeof(buf));
  c = 1 - c;
  sprintf(ptr, "%04lx ", val);
  if (flags & 0x01)
    strcat(ptr, "???? ");
  else
    strcat(ptr, "     ");
  if (flags & 0x08)
    strcat(ptr, "str ");
  else
    strcat(ptr, "    ");
  if (flags & 0x20)
    strcat(ptr, "eqm ");
  else
    strcat(ptr, "    ");
  if (flags & (0x40 | 0x10)) {
    strcat(ptr, "(");
  } else
    strcat(ptr, " ");
  if (flags & (0x40))
    strcat(ptr, "R");
  else
    strcat(ptr, " ");
  if (flags & (0x10))
    strcat(ptr, "S");
  else
    strcat(ptr, " ");
  if (flags & (0x40 | 0x10)) {
    strcat(ptr, ")");
  } else
    strcat(ptr, " ");
  return ptr;
}


x86 assembly (clang, -O0):
<sftos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsbl 0x3318(%rip),%edx
lea    0x2f03(%rip),%rcx
mov    %rcx,%rax
add    $0x207,%rax
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x18(%rbp)
lea    0x2ee8(%rip),%rdi
xor    %esi,%esi
mov    $0x40e,%edx
call   1030 <memset@plt>
movsbl 0x32e3(%rip),%ecx
mov    $0x1,%eax
sub    %ecx,%eax
mov    %al,0x32d6(%rip)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe69(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11c0 <sftos+0x90>
mov    -0x18(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1040 <strcat@plt>
jmp    11d0 <sftos+0xa0>
mov    -0x18(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1040 <strcat@plt>
mov    -0xc(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     11f4 <sftos+0xc4>
mov    -0x18(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1040 <strcat@plt>
jmp    1204 <sftos+0xd4>
mov    -0x18(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1040 <strcat@plt>
mov    -0xc(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     1228 <sftos+0xf8>
mov    -0x18(%rbp),%rdi
lea    0xdfa(%rip),%rsi
call   1040 <strcat@plt>
jmp    1238 <sftos+0x108>
mov    -0x18(%rbp),%rdi
lea    0xddb(%rip),%rsi
call   1040 <strcat@plt>
mov    -0xc(%rbp),%eax
and    $0x50,%eax
cmp    $0x0,%eax
je     125c <sftos+0x12c>
mov    -0x18(%rbp),%rdi
lea    0xdcb(%rip),%rsi
call   1040 <strcat@plt>
jmp    126c <sftos+0x13c>
mov    -0x18(%rbp),%rdi
lea    0xdaa(%rip),%rsi
call   1040 <strcat@plt>
mov    -0xc(%rbp),%eax
and    $0x40,%eax
cmp    $0x0,%eax
je     1290 <sftos+0x160>
mov    -0x18(%rbp),%rdi
lea    0xd99(%rip),%rsi
call   1040 <strcat@plt>
jmp    12a0 <sftos+0x170>
mov    -0x18(%rbp),%rdi
lea    0xd76(%rip),%rsi
call   1040 <strcat@plt>
mov    -0xc(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     12c4 <sftos+0x194>
mov    -0x18(%rbp),%rdi
lea    0xd67(%rip),%rsi
call   1040 <strcat@plt>
jmp    12d4 <sftos+0x1a4>
mov    -0x18(%rbp),%rdi
lea    0xd42(%rip),%rsi
call   1040 <strcat@plt>
mov    -0xc(%rbp),%eax
and    $0x50,%eax
cmp    $0x0,%eax
je     12f8 <sftos+0x1c8>
mov    -0x18(%rbp),%rdi
lea    0xd35(%rip),%rsi
call   1040 <strcat@plt>
jmp    1308 <sftos+0x1d8>
mov    -0x18(%rbp),%rdi
lea    0xd0e(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sftos>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
cmpb   $0x0,0x331a(%rip)
lea    0x310c(%rip),%rbx
lea    0x2efe(%rip),%rdi
cmovne %rdi,%rbx
xor    %esi,%esi
mov    $0x40e,%edx
call   1030 <memset@plt>
mov    $0x1,%al
sub    0x32f4(%rip),%al
mov    %al,0x32ee(%rip)
lea    0xe89(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <sprintf@plt>
test   $0x1,%r15b
lea    0xe80(%rip),%rax
lea    0xe73(%rip),%rsi
cmove  %rax,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x8,%r15b
lea    0xe63(%rip),%rbp
lea    0xe61(%rip),%rsi
cmove  %rbp,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x20,%r15b
lea    0xe4f(%rip),%rsi
cmove  %rbp,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x50,%r15b
lea    0xe31(%rip),%r14
lea    0xe36(%rip),%rsi
cmove  %r14,%rsi
lea    0xe31(%rip),%rbp
cmove  %r14,%rbp
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x40,%r15b
lea    0xe16(%rip),%rsi
cmove  %r14,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x10,%r15b
lea    0xe01(%rip),%rsi
cmove  %r14,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@sftos.buf = internal global [1038 x i8] zeroinitializer
@sftos.c = internal global i8 0
@.str = [7 x i8] c"%04lx \00"
@.str.1 = [6 x i8] c"???? \00"
@.str.2 = [6 x i8] c" \00"
@.str.3 = [5 x i8] c"str \00"
@.str.4 = [5 x i8] c" \00"
@.str.5 = [5 x i8] c"eqm \00"
@.str.6 = [2 x i8] c"(\00"
@.str.7 = [2 x i8] c" \00"
@.str.8 = [2 x i8] c"R\00"
@.str.9 = [2 x i8] c"S\00"
@.str.10 = [2 x i8] c")\00"
define i8* @sftos(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
store i64 %0, i64* %3
store i32 %1, i32* %4
%6 = load i8, i8* @sftos.c
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 0
%9 = zext i1 %8 to i64
%10 = select i1 %8, i8* getelementptr inbounds ([1038 x i8], [1038 x i8]* @sftos.buf, i64 0, i64 0), i8* getelementptr inbounds ([1038 x i8], [1038 x i8]* @sftos.buf, i64 0, i64 519)
store i8* %10, i8** %5
%11 = call i32 @memset(i8* getelementptr inbounds ([1038 x i8], [1038 x i8]* @sftos.buf, i64 0, i64 0), i32 0, i32 1038)
%12 = load i8, i8* @sftos.c
%13 = sext i8 %12 to i32
%14 = sub nsw i32 1, %13
%15 = trunc i32 %14 to i8
store i8 %15, i8* @sftos.c
%16 = load i8*, i8** %5
%17 = load i64, i64* %3
%18 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %17)
%19 = load i32, i32* %4
%20 = and i32 %19, 1
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = load i8*, i8** %5
%24 = call i32 @strcat(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %28
25: ; preds = %2
%26 = load i8*, i8** %5
%27 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %25, %22
%29 = load i32, i32* %4
%30 = and i32 %29, 8
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i8*, i8** %5
%34 = call i32 @strcat(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %38
35: ; preds = %28
%36 = load i8*, i8** %5
%37 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %35, %32
%39 = load i32, i32* %4
%40 = and i32 %39, 32
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load i8*, i8** %5
%44 = call i32 @strcat(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %48
45: ; preds = %38
%46 = load i8*, i8** %5
%47 = call i32 @strcat(i8* %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %45, %42
%49 = load i32, i32* %4
%50 = and i32 %49, 80
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = load i8*, i8** %5
%54 = call i32 @strcat(i8* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %58
55: ; preds = %48
%56 = load i8*, i8** %5
%57 = call i32 @strcat(i8* %56, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %58
58: ; preds = %55, %52
%59 = load i32, i32* %4
%60 = and i32 %59, 64
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %58
%63 = load i8*, i8** %5
%64 = call i32 @strcat(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %68
65: ; preds = %58
%66 = load i8*, i8** %5
%67 = call i32 @strcat(i8* %66, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %68
68: ; preds = %65, %62
%69 = load i32, i32* %4
%70 = and i32 %69, 16
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %68
%73 = load i8*, i8** %5
%74 = call i32 @strcat(i8* %73, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %78
75: ; preds = %68
%76 = load i8*, i8** %5
%77 = call i32 @strcat(i8* %76, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %78
78: ; preds = %75, %72
%79 = load i32, i32* %4
%80 = and i32 %79, 80
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %78
%83 = load i8*, i8** %5
%84 = call i32 @strcat(i8* %83, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %88
85: ; preds = %78
%86 = load i8*, i8** %5
%87 = call i32 @strcat(i8* %86, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %88
88: ; preds = %85, %82
%89 = load i8*, i8** %5
ret i8* %89
}

LLVM IR (-O2):
@sftos.buf = internal global [1038 x i8] zeroinitializer
@sftos.c = internal unnamed_addr global i8 0
@.str = [7 x i8] c"%04lx \00"
@.str.1 = [6 x i8] c"???? \00"
@.str.2 = [6 x i8] c" \00"
@.str.3 = [5 x i8] c"str \00"
@.str.4 = [5 x i8] c" \00"
@.str.5 = [5 x i8] c"eqm \00"
@.str.6 = [2 x i8] c"(\00"
@.str.7 = [2 x i8] c" \00"
@.str.8 = [2 x i8] c"R\00"
@.str.9 = [2 x i8] c"S\00"
@.str.10 = [2 x i8] c")\00"
define i8* @sftos(i64 %0, i32 %1) {
%3 = load i8, i8* @sftos.c
%4 = icmp eq i8 %3, 0
%5 = select i1 %4, i8* getelementptr inbounds ([1038 x i8], [1038 x i8]* @sftos.buf, i64 0, i64 519), i8* getelementptr inbounds ([1038 x i8], [1038 x i8]* @sftos.buf, i64 0, i64 0)
%6 = tail call i32 @memset(i8* getelementptr inbounds ([1038 x i8], [1038 x i8]* @sftos.buf, i64 0, i64 0), i32 0, i32 1038)
%7 = load i8, i8* @sftos.c
%8 = sub i8 1, %7
store i8 %8, i8* @sftos.c
%9 = tail call i32 @sprintf(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %0)
%10 = and i32 %1, 1
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%13 = tail call i32 @strcat(i8* %5, i8* %12)
%14 = and i32 %1, 8
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
%17 = tail call i32 @strcat(i8* %5, i8* %16)
%18 = and i32 %1, 32
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0)
%21 = tail call i32 @strcat(i8* %5, i8* %20)
%22 = and i32 %1, 80
%23 = icmp eq i32 %22, 0
%24 = select i1 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0)
%25 = tail call i32 @strcat(i8* %5, i8* %24)
%26 = and i32 %1, 64
%27 = icmp eq i32 %26, 0
%28 = select i1 %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0)
%29 = tail call i32 @strcat(i8* %5, i8* %28)
%30 = and i32 %1, 16
%31 = icmp eq i32 %30, 0
%32 = select i1 %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0)
%33 = tail call i32 @strcat(i8* %5, i8* %32)
%34 = select i1 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0)
%35 = tail call i32 @strcat(i8* %5, i8* %34)
ret i8* %5
}