#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*/ add_0(char *, int);
char *dec2hex(int, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ strcpy(char *, char *);
void calc_length(char *listing_line, char *addr) {
  char op1[50], op2[50];
  int iop1, iop2, i;
  strcpy(op1, addr);
  for (i = 1; i <= 6; i++)
    op2[i - 1] = listing_line[i];
  op2[i - 1] = 0;
  sscanf(op1, "%x", &iop1);
  sscanf(op2, "%x", &iop2);
  strcpy(op1, dec2hex(iop1 - iop2, op1));
  add_0(op1, 2);
  for (i = 7; i <= 8; i++)
    listing_line[i] = op1[i - 7];
}


x86 assembly (clang, -O0):
<calc_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x9c(%rbp)
cmpl   $0x6,-0x9c(%rbp)
jg     11ab <calc_length+0x6b>
mov    -0x8(%rbp),%rax
movslq -0x9c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x9c(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    116a <calc_length+0x2a>
mov    -0x9c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x50(%rbp),%rdi
lea    0xe37(%rip),%rsi
lea    -0x94(%rbp),%rdx
call   1040 <sscanf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe1d(%rip),%rsi
lea    -0x98(%rbp),%rdx
call   1040 <sscanf@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x94(%rbp),%edi
sub    -0x98(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   1050 <dec2hex@plt>
mov    -0xa8(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
lea    -0x50(%rbp),%rdi
mov    $0x2,%esi
call   1060 <add_0@plt>
movl   $0x7,-0x9c(%rbp)
cmpl   $0x8,-0x9c(%rbp)
jg     1274 <calc_length+0x134>
mov    -0x9c(%rbp),%eax
sub    $0x7,%eax
cltq
mov    -0x50(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x9c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    1236 <calc_length+0xf6>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_length>:
push   %r15
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    %rdi,%rbx
lea    0x50(%rsp),%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    0x1(%rbx),%eax
mov    %eax,0x10(%rsp)
movzwl 0x5(%rbx),%eax
mov    %ax,0x14(%rsp)
movb   $0x0,0x16(%rsp)
lea    0xe88(%rip),%r15
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <sscanf@plt>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rdx
mov    %r15,%rsi
call   1040 <sscanf@plt>
mov    0xc(%rsp),%edi
sub    0x8(%rsp),%edi
mov    %r14,%rsi
call   1050 <dec2hex@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    $0x2,%esi
call   1060 <add_0@plt>
movzwl 0x50(%rsp),%eax
mov    %ax,0x7(%rbx)
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%x\00"
define void @calc_length(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [50 x i8]
%6 = alloca [50 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%11 = load i8*, i8** %4
%12 = call i32 @strcpy(i8* %10, i8* %11)
store i32 1, i32* %9
br label %13
13: ; preds = %26, %2
%14 = load i32, i32* %9
%15 = icmp sle i32 %14, 6
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = load i32, i32* %9
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 %24
store i8 %21, i8* %25
br label %26
26: ; preds = %16
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 1
store i32 %28, i32* %9
br label %13
29: ; preds = %13
%30 = load i32, i32* %9
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 %32
store i8 0, i8* %33
%34 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%35 = call i32 @sscanf(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%36 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%37 = call i32 @sscanf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%38 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%39 = load i32, i32* %7
%40 = load i32, i32* %8
%41 = sub nsw i32 %39, %40
%42 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%43 = call i8* @dec2hex(i32 %41, i8* %42)
%44 = call i32 @strcpy(i8* %38, i8* %43)
%45 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%46 = call i32 @add_0(i8* %45, i32 2)
store i32 7, i32* %9
br label %47
47: ; preds = %60, %29
%48 = load i32, i32* %9
%49 = icmp sle i32 %48, 8
br i1 %49, label %50, label %63
50: ; preds = %47
%51 = load i32, i32* %9
%52 = sub nsw i32 %51, 7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 %53
%55 = load i8, i8* %54
%56 = load i8*, i8** %3
%57 = load i32, i32* %9
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8 %55, i8* %59
br label %60
60: ; preds = %50
%61 = load i32, i32* %9
%62 = add nsw i32 %61, 1
store i32 %62, i32* %9
br label %47
63: ; preds = %47
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%x\00"
define void @calc_length(i8* nocapture %0, i8* %1) {
%3 = alloca [50 x i8]
%4 = alloca [50 x i8]
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%6 = alloca i32
%7 = alloca i32
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%10 = bitcast i32* %6 to i8*
%11 = bitcast i32* %7 to i8*
%12 = call i32 @strcpy(i8* %8, i8* %1)
%13 = getelementptr i8, i8* %0, i64 1
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 6
store i8 0, i8* %14
%15 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%16 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = sub nsw i32 %17, %18
%20 = call i8* @dec2hex(i32 %19, i8* %8)
%21 = call i32 @strcpy(i8* %8, i8* %20)
%22 = call i32 @add_0(i8* %8, i32 2)
%23 = getelementptr i8, i8* %0, i64 7
%24 = bitcast [50 x i8]* %3 to i16*
%25 = bitcast i8* %23 to i16*
%26 = load i16, i16* %24
store i16 %26, i16* %25
ret void
}