#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 *, unsigned char const);
void disasm_simm8(char *dst, const unsigned char *src) {
  if (src[0] < 0x80) {
    sprintf(dst, "+%02X", src[0]);
  } else {
    sprintf(dst, "-%02X", (~src[0] + 1) & 0xff);
  }
}


x86 assembly (clang, -O0):
<disasm_simm8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x80,%eax
jge    114e <disasm_simm8+0x3e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
lea    0xebf(%rip),%rsi
movzbl (%rax),%edx
call   1030 <sprintf@plt>
jmp    1173 <disasm_simm8+0x63>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
xor    $0xffffffff,%eax
add    $0x1,%eax
and    $0xff,%eax
lea    0xe9b(%rip),%rsi
movzbl %al,%edx
call   1030 <sprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disasm_simm8>:
mov    (%rsi),%al
test   %al,%al
js     1125 <disasm_simm8+0x15>
movzbl %al,%edx
lea    0xee0(%rip),%rsi
jmp    1030 <sprintf@plt>
neg    %al
movzbl %al,%edx
lea    0xed5(%rip),%rsi
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"+%02X\00"
@.str.1 = [6 x i8] c"-%02X\00"
define void @disasm_simm8(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
%9 = icmp slt i32 %8, 128
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %14)
br label %27
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = xor i32 %21, -1
%23 = add nsw i32 %22, 1
%24 = and i32 %23, 255
%25 = trunc i32 %24 to i8
%26 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %25)
br label %27
27: ; preds = %16, %10
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"+%02X\00"
@.str.1 = [6 x i8] c"-%02X\00"
define void @disasm_simm8(i8* nocapture writeonly %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp sgt i8 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %3)
br label %10
7: ; preds = %2
%8 = sub i8 0, %3
%9 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %8)
br label %10
10: ; preds = %7, %5
ret void
}