#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void main() {
  char icode[10][30], str[20], opr[10];
  int i = 0;
  printf("\n Enter the set of intermediate code (terminated by exit):\n");
  do {
    scanf("%s", icode[i]);
  } while (strcmp(icode[i++], "exit") != 0);
  printf("\n target code generation");
  printf("\n************************");
  i = 0;
  do {
    strcpy(str, icode[i]);
    switch (str[3]) {
    case '+':
      strcpy(opr, "ADD");
      break;
    case '-':
      strcpy(opr, "SUB");
      break;
    case '*':
      strcpy(opr, "MUL");
      break;
    case '/':
      strcpy(opr, "DIV");
      break;
    }
    printf("\n\tMov %c,R%d", str[2], i);
    printf("\n\t%s%c,R%d", opr, str[4], i);
    printf("\n\tMov R%d,%c", i, str[0]);
  } while (strcmp(icode[++i], "exit") != 0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
movl   $0x0,-0x160(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x160(%rbp),%rax
lea    -0x130(%rbp),%rsi
imul   $0x1e,%rax,%rax
add    %rax,%rsi
lea    0xed5(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x160(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x160(%rbp)
cltq
lea    -0x130(%rbp),%rdi
imul   $0x1e,%rax,%rax
add    %rax,%rdi
lea    0xeab(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1163 <main+0x23>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x160(%rbp)
movslq -0x160(%rbp),%rcx
mov    %rcx,%rax
shl    $0x5,%rax
sub    %rcx,%rax
sub    %rcx,%rax
lea    -0x130(%rbp,%rax,1),%rsi
ff
lea    -0x150(%rbp),%rdi
call   1030 <strcpy@plt>
movsbl -0x14d(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x168(%rbp)
sub    $0x5,%eax
ja     1297 <main+0x157>
mov    -0x168(%rbp),%rax
lea    0xdcd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x15a(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1297 <main+0x157>
lea    -0x15a(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1297 <main+0x157>
lea    -0x15a(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1297 <main+0x157>
lea    -0x15a(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1030 <strcpy@plt>
movsbl -0x14e(%rbp),%esi
mov    -0x160(%rbp),%edx
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x15a(%rbp),%rsi
movsbl -0x14c(%rbp),%edx
mov    -0x160(%rbp),%ecx
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x160(%rbp),%esi
movsbl -0x150(%rbp),%edx
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x160(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x160(%rbp)
cltq
lea    -0x130(%rbp),%rdi
imul   $0x1e,%rax,%rax
add    %rax,%rdi
lea    0xd42(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11e1 <main+0xa1>
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x158,%rsp
lea    0xf08(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rbx
lea    0xe87(%rip),%r14
lea    0xe83(%rip),%rbp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <strcmp@plt>
add    $0x1e,%rbx
test   %rax,%rax
jne    1180 <main+0x30>
lea    0xe62(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe6d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x20(%rsp),%rbx
lea    0x16(%rsp),%r15
lea    0xe8c(%rip),%r13
lea    0xe90(%rip),%rbp
lea    0xe29(%rip),%r14
xor    %r12d,%r12d
jmp    1234 <main+0xe4>
nop
movsbl 0x2(%rsp),%esi
lea    0xe5f(%rip),%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
movsbl 0x4(%rsp),%edx
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12d,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
movsbl (%rsp),%edx
mov    %rbp,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1e,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
add    $0x1,%r12d
test   %rax,%rax
je     1273 <main+0x123>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
movsbq 0x3(%rsp),%rax
add    $0xffffffffffffffd6,%rax
cmp    $0x5,%eax
ja     11e0 <main+0x90>
mov    $0x2b,%ecx
bt     %eax,%ecx
jae    11e0 <main+0x90>
lea    0xe4d(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
jmp    11e0 <main+0x90>
add    $0x158,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [60 x i8] c"\0A Enter the set of intermediate code (terminated by exit):\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c"exit\00"
@.str.3 = [25 x i8] c"\0A target code generation\00"
@.str.4 = [26 x i8] c"\0A************************\00"
@.str.5 = [4 x i8] c"ADD\00"
@.str.6 = [4 x i8] c"SUB\00"
@.str.7 = [4 x i8] c"MUL\00"
@.str.8 = [4 x i8] c"DIV\00"
@.str.9 = [13 x i8] c"\0A\09Mov %c,R%d\00"
@.str.10 = [11 x i8] c"\0A\09%s%c,R%d\00"
@.str.11 = [13 x i8] c"\0A\09Mov R%d,%c\00"
define void @main() {
%1 = alloca [10 x [30 x i8]]
%2 = alloca [20 x i8]
%3 = alloca [10 x i8]
%4 = alloca i32
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %12, %0
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [10 x [30 x i8]], [10 x [30 x i8]]* %1, i64 0, i64 %8
%10 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %6
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
store i32 %14, i32* %4
%15 = sext i32 %13 to i64
%16 = getelementptr inbounds [10 x [30 x i8]], [10 x [30 x i8]]* %1, i64 0, i64 %15
%17 = getelementptr inbounds [30 x i8], [30 x i8]* %16, i64 0, i64 0
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %6, label %20
20: ; preds = %12
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %4
br label %23
23: ; preds = %62, %20
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [10 x [30 x i8]], [10 x [30 x i8]]* %1, i64 0, i64 %26
%28 = getelementptr inbounds [30 x i8], [30 x i8]* %27, i64 0, i64 0
%29 = call i32 @strcpy(i8* %24, i8* %28)
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 3
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
switch i32 %32, label %45 [
i32 43, label %33
i32 45, label %36
i32 42, label %39
i32 47, label %42
]
33: ; preds = %23
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%35 = call i32 @strcpy(i8* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %45
36: ; preds = %23
%37 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%38 = call i32 @strcpy(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %45
39: ; preds = %23
%40 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%41 = call i32 @strcpy(i8* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
br label %45
42: ; preds = %23
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%44 = call i32 @strcpy(i8* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
br label %45
45: ; preds = %23, %42, %39, %36, %33
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 2
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = load i32, i32* %4
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i32 %48, i32 %49)
%51 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%52 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 4
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = load i32, i32* %4
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i8* %51, i32 %54, i32 %55)
%57 = load i32, i32* %4
%58 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i32 %57, i32 %60)
br label %62
62: ; preds = %45
%63 = load i32, i32* %4
%64 = add nsw i32 %63, 1
store i32 %64, i32* %4
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [10 x [30 x i8]], [10 x [30 x i8]]* %1, i64 0, i64 %65
%67 = getelementptr inbounds [30 x i8], [30 x i8]* %66, i64 0, i64 0
%68 = call i64 @strcmp(i8* %67, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%69 = icmp ne i64 %68, 0
br i1 %69, label %23, label %70
70: ; preds = %62
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c"exit\00"
@.str.3 = [25 x i8] c"\0A target code generation\00"
@.str.4 = [26 x i8] c"\0A************************\00"
@.str.5 = [4 x i8] c"ADD\00"
@.str.6 = [4 x i8] c"SUB\00"
@.str.7 = [4 x i8] c"MUL\00"
@.str.8 = [4 x i8] c"DIV\00"
@.str.9 = [13 x i8] c"\0A\09Mov %c,R%d\00"
@.str.10 = [11 x i8] c"\0A\09%s%c,R%d\00"
@.str.11 = [13 x i8] c"\0A\09Mov R%d,%c\00"
@str = [59 x i8] c"\0A Enter the set of intermediate code (terminated by exit):\00"
@reltable.main = [6 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.7 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.5 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.5 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.6 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.5 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.8 to i64), i64 ptrtoint ([6 x i32]* @reltable.main to i64)) to i32)]
define void @main() {
%1 = alloca [10 x [30 x i8]]
%2 = alloca [20 x i8]
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x [30 x i8]], [10 x [30 x i8]]* %1, i64 0, i64 0, i64 0
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %8, %0
%9 = phi i64 [ %12, %8 ], [ 0, %0 ]
%10 = getelementptr inbounds [10 x [30 x i8]], [10 x [30 x i8]]* %1, i64 0, i64 %9, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = add nuw i64 %9, 1
%13 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %8
15: ; preds = %8
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 3
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 2
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 4
br label %21
21: ; preds = %39, %15
%22 = phi i64 [ %50, %39 ], [ 0, %15 ]
%23 = getelementptr inbounds [10 x [30 x i8]], [10 x [30 x i8]]* %1, i64 0, i64 %22, i64 0
%24 = call i32 @strcpy(i8* %5, i8* %23)
%25 = load i8, i8* %18
%26 = sext i8 %25 to i32
%27 = add nsw i32 %26, -42
%28 = icmp ult i32 %27, 6
br i1 %28, label %29, label %39
29: ; preds = %21
%30 = trunc i32 %27 to i8
%31 = lshr i8 43, %30
%32 = and i8 %31, 1
%33 = icmp eq i8 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %29
%35 = sext i32 %27 to i64
%36 = shl i64 %35, 2
%37 = call i8* @llvm.load.relative.i64(i8* bitcast ([6 x i32]* @reltable.main to i8*), i64 %36)
%38 = call i32 @strcpy(i8* %6, i8* %37)
br label %39
39: ; preds = %29, %21, %34
%40 = load i8, i8* %19
%41 = sext i8 %40 to i32
%42 = trunc i64 %22 to i32
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i32 %41, i32 %42)
%44 = load i8, i8* %20
%45 = sext i8 %44 to i32
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i8* %6, i32 %45, i32 %42)
%47 = load i8, i8* %5
%48 = sext i8 %47 to i32
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i32 %42, i32 %48)
%50 = add nuw i64 %22, 1
%51 = getelementptr inbounds [10 x [30 x i8]], [10 x [30 x i8]]* %1, i64 0, i64 %50, i64 0
%52 = call i64 @strcmp(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %21
54: ; preds = %39
ret void
}