#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 */
int /*<<< orphan*/ sprintf(char *, char *, ...);
char *make_signed_hex_str_16(unsigned int val) {
  static char str[20];
  val &= 0xffff;
  if (val == 0x8000)
    sprintf(str, "-$8000");
  else if (val & 0x8000)
    sprintf(str, "-$%x", (0 - val) & 0x7fff);
  else
    sprintf(str, "$%x", val & 0x7fff);
  return str;
}


x86 assembly (clang, -O0):
<make_signed_hex_str_16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x8000,-0x4(%rbp)
jne    114d <make_signed_hex_str_16+0x3d>
lea    0x2f06(%rip),%rdi
lea    0xebf(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11a6 <make_signed_hex_str_16+0x96>
mov    -0x4(%rbp),%eax
and    $0x8000,%eax
cmp    $0x0,%eax
je     1183 <make_signed_hex_str_16+0x73>
xor    %edx,%edx
sub    -0x4(%rbp),%edx
and    $0x7fff,%edx
lea    0x2ed0(%rip),%rdi
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11a1 <make_signed_hex_str_16+0x91>
mov    -0x4(%rbp),%edx
and    $0x7fff,%edx
lea    0x2ead(%rip),%rdi
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11a6 <make_signed_hex_str_16+0x96>
lea    0x2e93(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_signed_hex_str_16>:
push   %rax
mov    %edi,%edx
movzwl %dx,%eax
cmp    $0x8000,%eax
jne    1133 <make_signed_hex_str_16+0x23>
movl   $0x303030,0x2f1c(%rip)
movl   $0x3038242d,0x2f0f(%rip)
24 38 30
jmp    116e <make_signed_hex_str_16+0x5e>
test   $0x8000,%edx
jne    1151 <make_signed_hex_str_16+0x41>
and    $0x7fff,%edx
lea    0x2ef8(%rip),%rdi
lea    0xeb9(%rip),%rsi
jmp    1167 <make_signed_hex_str_16+0x57>
neg    %edx
and    $0x7fff,%edx
lea    0x2ee0(%rip),%rdi
lea    0xea0(%rip),%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
lea    0x2ecb(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@make_signed_hex_str_16.str = internal global [20 x i8] zeroinitializer
@.str = [7 x i8] c"-$8000\00"
@.str.1 = [5 x i8] c"-$%x\00"
@.str.2 = [4 x i8] c"$%x\00"
define i8* @make_signed_hex_str_16(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = and i32 %3, 65535
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 32768
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @make_signed_hex_str_16.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %23
9: ; preds = %1
%10 = load i32, i32* %2
%11 = and i32 %10, 32768
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i32, i32* %2
%15 = sub i32 0, %14
%16 = and i32 %15, 32767
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @make_signed_hex_str_16.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %22
18: ; preds = %9
%19 = load i32, i32* %2
%20 = and i32 %19, 32767
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @make_signed_hex_str_16.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %13
br label %23
23: ; preds = %22, %7
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @make_signed_hex_str_16.str, i64 0, i64 0)
}

LLVM IR (-O2):
@make_signed_hex_str_16.str = internal global [20 x i8] zeroinitializer
@.str = [7 x i8] c"-$8000\00"
@.str.1 = [5 x i8] c"-$%x\00"
@.str.2 = [4 x i8] c"$%x\00"
define i8* @make_signed_hex_str_16(i32 %0) {
%2 = and i32 %0, 65535
%3 = icmp eq i32 %2, 32768
br i1 %3, label %4, label %5
4: ; preds = %1
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 dereferenceable(7) getelementptr inbounds ([20 x i8], [20 x i8]* @make_signed_hex_str_16.str, i64 0, i64 0), i8* align 1 dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 7, i1 false)
br label %15
5: ; preds = %1
%6 = and i32 %0, 32768
%7 = icmp eq i32 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = sub i32 0, %0
%10 = and i32 %9, 32767
%11 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @make_signed_hex_str_16.str, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %15
12: ; preds = %5
%13 = and i32 %0, 32767
%14 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @make_signed_hex_str_16.str, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %8, %12, %4
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @make_signed_hex_str_16.str, i64 0, i64 0)
}