#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*/ lineprint2(char *, long, unsigned char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, unsigned long);
void relative(char *outf, long ctr, unsigned char *op, char *str) {
  char buf[256];
  long newadd;
  int offset = (int)*(op + 1);
  if (offset >= 128)
    offset -= 256;
  newadd = (ctr + 2) + offset;
  sprintf(buf, "%-4s $%04lX", str, (unsigned long)newadd);
  lineprint2(outf, ctr, op, buf);
}


x86 assembly (clang, -O0):
<relative>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    %eax,-0x12c(%rbp)
cmpl   $0x80,-0x12c(%rbp)
jl     116a <relative+0x4a>
mov    -0x12c(%rbp),%eax
sub    $0x100,%eax
mov    %eax,-0x12c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x2,%rax
movslq -0x12c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x128(%rbp),%rcx
lea    0xe64(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x120(%rbp),%rcx
call   1030 <lineprint2@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<relative>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
movzbl 0x1(%rdx),%eax
lea    -0x100(%rax),%edx
test   %al,%al
cmovns %eax,%edx
movslq %edx,%rax
add    %rsi,%rax
add    $0x2,%rax
lea    0xea9(%rip),%rsi
mov    %rsp,%r12
mov    %r12,%rdi
mov    %rcx,%rdx
mov    %rax,%rcx
call   1040 <sprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1030 <lineprint2@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%-4s $%04lX\00"
define void @relative(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [256 x i8]
%10 = alloca i64
%11 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%12 = load i8*, i8** %7
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
store i32 %15, i32* %11
%16 = load i32, i32* %11
%17 = icmp sge i32 %16, 128
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = load i32, i32* %11
%20 = sub nsw i32 %19, 256
store i32 %20, i32* %11
br label %21
21: ; preds = %18, %4
%22 = load i64, i64* %6
%23 = add nsw i64 %22, 2
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = add nsw i64 %23, %25
store i64 %26, i64* %10
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%28 = load i8*, i8** %8
%29 = load i64, i64* %10
%30 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %28, i64 %29)
%31 = load i8*, i8** %5
%32 = load i64, i64* %6
%33 = load i8*, i8** %7
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%35 = call i32 @lineprint2(i8* %31, i64 %32, i8* %33, i8* %34)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%-4s $%04lX\00"
define void @relative(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%7 = getelementptr inbounds i8, i8* %2, i64 1
%8 = load i8, i8* %7
%9 = zext i8 %8 to i32
%10 = icmp slt i8 %8, 0
%11 = or i32 %9, -256
%12 = select i1 %10, i32 %11, i32 %9
%13 = add nsw i64 %1, 2
%14 = sext i32 %12 to i64
%15 = add nsw i64 %13, %14
%16 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %3, i64 %15)
%17 = call i32 @lineprint2(i8* %0, i64 %1, i8* %2, i8* %6)
ret void
}