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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char, char, ...);
int /*<<< orphan*/ printf(char *, int);
void ldi(FILE *fo, char input[], int counter) {
  char number;
  char saveReg;
  if (input[4] == '\'') {
    if (input[5] == '\\') {
      switch (input[6]) {
      case '0':
        number = 0;
        break;
      case 'n':
        number = '\n';
        break;
      case 't':
        number = '\t';
        break;
      default:
        printf("Unable to resolve code written at line %d\n", counter);
        return;
      }
      saveReg = input[10];
    } else {
      number = input[5];
      saveReg = input[9];
    }
    fprintf(fo, "d%02x%c ", number, saveReg);
  } else {
    if (input[8] == '\n' || input[8] == ' ') {
      printf("Unable to resolve code written at line %d\n", counter);
      return;
    } else
      fprintf(fo, "d%c%c%c ", input[4], input[5], input[8]);
  }
  return;
}


x86 assembly (clang, -O0):
<ldi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x4(%rax),%eax
cmp    $0x27,%eax
jne    1203 <ldi+0xe3>
mov    -0x10(%rbp),%rax
movsbl 0x5(%rax),%eax
cmp    $0x5c,%eax
jne    11ce <ldi+0xae>
mov    -0x10(%rbp),%rax
movsbl 0x6(%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x30,%eax
je     1190 <ldi+0x70>
jmp    116e <ldi+0x4e>
mov    -0x1c(%rbp),%eax
sub    $0x6e,%eax
je     1199 <ldi+0x79>
jmp    117f <ldi+0x5f>
mov    -0x1c(%rbp),%eax
sub    $0x74,%eax
je     11a2 <ldi+0x82>
jmp    11ab <ldi+0x8b>
movb   $0x0,-0x15(%rbp)
jmp    11bf <ldi+0x9f>
movb   $0xa,-0x15(%rbp)
jmp    11bf <ldi+0x9f>
movb   $0x9,-0x15(%rbp)
jmp    11bf <ldi+0x9f>
mov    -0x14(%rbp),%esi
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
jmp    1272 <ldi+0x152>
mov    -0x10(%rbp),%rax
mov    0xa(%rax),%al
mov    %al,-0x16(%rbp)
jmp    11e2 <ldi+0xc2>
mov    -0x10(%rbp),%rax
mov    0x5(%rax),%al
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rax
mov    0x9(%rax),%al
mov    %al,-0x16(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x15(%rbp),%al
lea    0xe3b(%rip),%rsi
movsbl %al,%edx
movsbl -0x16(%rbp),%ecx
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    126d <ldi+0x14d>
mov    -0x10(%rbp),%rax
movsbl 0x8(%rax),%eax
cmp    $0xa,%eax
je     1225 <ldi+0x105>
mov    -0x10(%rbp),%rax
movsbl 0x8(%rax),%eax
cmp    $0x20,%eax
jne    1239 <ldi+0x119>
mov    -0x14(%rbp),%esi
lea    0xdd1(%rip),%rdi
call   1030 <printf@plt>
jmp    1272 <ldi+0x152>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%cl
mov    -0x10(%rbp),%rax
mov    0x5(%rax),%al
mov    -0x10(%rbp),%rdx
movsbl 0x8(%rdx),%r8d
lea    0xdd9(%rip),%rsi
movsbl %cl,%edx
movsbl %al,%ecx
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    126d <ldi+0x14d>
jmp    1272 <ldi+0x152>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ldi>:
mov    0x4(%rsi),%al
cmp    $0x27,%al
jne    114f <ldi+0x2f>
mov    0x5(%rsi),%al
mov    $0x9,%ecx
cmp    $0x5c,%al
jne    1189 <ldi+0x69>
movsbl 0x6(%rsi),%eax
mov    $0xa,%ecx
cmp    $0x30,%eax
je     1183 <ldi+0x63>
cmp    $0x74,%eax
je     1187 <ldi+0x67>
cmp    $0x6e,%eax
jne    1160 <ldi+0x40>
mov    $0xa,%al
jmp    1189 <ldi+0x69>
movsbl 0x8(%rsi),%r8d
cmp    $0x20,%r8d
je     1160 <ldi+0x40>
cmp    $0xa,%r8b
jne    116e <ldi+0x4e>
lea    0xe99(%rip),%rdi
mov    %edx,%esi
jmp    1030 <printf@plt>
movsbl 0x5(%rsi),%ecx
movsbl %al,%edx
lea    0xeb8(%rip),%rsi
xor    %eax,%eax
jmp    1040 <fprintf@plt>
xor    %eax,%eax
jmp    1189 <ldi+0x69>
mov    $0x9,%al
movsbl (%rsi,%rcx,1),%ecx
movsbl %al,%edx
lea    0xe94(%rip),%rsi
xor    %eax,%eax
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"Unable to resolve code written at line %d\0A\00"
@.str.1 = [9 x i8] c"d%02x%c \00"
@.str.2 = [9 x i8] c"d%c%c%c \00"
define void @ldi(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %5
%10 = getelementptr inbounds i8, i8* %9, i64 4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 39
br i1 %13, label %14, label %47
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 5
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 92
br i1 %19, label %20, label %35
20: ; preds = %14
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 6
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
switch i32 %24, label %28 [
i32 48, label %25
i32 110, label %26
i32 116, label %27
]
25: ; preds = %20
store i8 0, i8* %7
br label %31
26: ; preds = %20
store i8 10, i8* %7
br label %31
27: ; preds = %20
store i8 9, i8* %7
br label %31
28: ; preds = %20
%29 = load i32, i32* %6
%30 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %29)
br label %77
31: ; preds = %27, %26, %25
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 10
%34 = load i8, i8* %33
store i8 %34, i8* %8
br label %42
35: ; preds = %14
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 5
%38 = load i8, i8* %37
store i8 %38, i8* %7
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 9
%41 = load i8, i8* %40
store i8 %41, i8* %8
br label %42
42: ; preds = %35, %31
%43 = load i32*, i32** %4
%44 = load i8, i8* %7
%45 = load i8, i8* %8
%46 = call i32 (i32*, i8*, i8, i8, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8 signext %44, i8 signext %45)
br label %76
47: ; preds = %3
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 8
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 10
br i1 %52, label %59, label %53
53: ; preds = %47
%54 = load i8*, i8** %5
%55 = getelementptr inbounds i8, i8* %54, i64 8
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 32
br i1 %58, label %59, label %62
59: ; preds = %53, %47
%60 = load i32, i32* %6
%61 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %60)
br label %77
62: ; preds = %53
%63 = load i32*, i32** %4
%64 = load i8*, i8** %5
%65 = getelementptr inbounds i8, i8* %64, i64 4
%66 = load i8, i8* %65
%67 = load i8*, i8** %5
%68 = getelementptr inbounds i8, i8* %67, i64 5
%69 = load i8, i8* %68
%70 = load i8*, i8** %5
%71 = getelementptr inbounds i8, i8* %70, i64 8
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = call i32 (i32*, i8*, i8, i8, ...) @fprintf(i32* %63, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8 signext %66, i8 signext %69, i32 %73)
br label %75
75: ; preds = %62
br label %76
76: ; preds = %75, %42
br label %77
77: ; preds = %76, %59, %28
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c"Unable to resolve code written at line %d\0A\00"
@.str.1 = [9 x i8] c"d%02x%c \00"
@.str.2 = [9 x i8] c"d%c%c%c \00"
define void @ldi(i32* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = getelementptr inbounds i8, i8* %1, i64 4
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 39
br i1 %6, label %7, label %25
7: ; preds = %3
%8 = getelementptr inbounds i8, i8* %1, i64 5
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 92
br i1 %10, label %11, label %19
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %1, i64 6
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
switch i32 %14, label %17 [
i32 48, label %19
i32 110, label %15
i32 116, label %16
]
15: ; preds = %11
br label %19
16: ; preds = %11
br label %19
17: ; preds = %11
%18 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %35
19: ; preds = %7, %15, %16, %11
%20 = phi i64 [ 10, %11 ], [ 10, %16 ], [ 10, %15 ], [ 9, %7 ]
%21 = phi i8 [ 0, %11 ], [ 9, %16 ], [ 10, %15 ], [ %9, %7 ]
%22 = getelementptr inbounds i8, i8* %1, i64 %20
%23 = load i8, i8* %22
%24 = tail call i32 (i32*, i8*, i8, i8, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8 signext %21, i8 signext %23)
br label %35
25: ; preds = %3
%26 = getelementptr inbounds i8, i8* %1, i64 8
%27 = load i8, i8* %26
switch i8 %27, label %30 [
i8 10, label %28
i8 32, label %28
]
28: ; preds = %25, %25
%29 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %35
30: ; preds = %25
%31 = sext i8 %27 to i32
%32 = getelementptr inbounds i8, i8* %1, i64 5
%33 = load i8, i8* %32
%34 = tail call i32 (i32*, i8*, i8, i8, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8 signext %5, i8 signext %33, i32 %31)
br label %35
35: ; preds = %19, %30, %28, %17
ret void
}