#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int strlen(char *);
char *getNewArithmeticOperation(char *left, char *right, int opCode) {
  int size = strlen(left) + strlen(right) + 8;
  char *result = (char *)malloc(size);
  switch (opCode) {
  case 0:
    snprintf(result, size, "ADD(%s; %s)", left, right);
    break;
  case 1:
    snprintf(result, size, "SUB(%s; %s)", left, right);
    break;
  case 2:
    snprintf(result, size, "MUL(%s; %s)", left, right);
    break;
  case 3:
    snprintf(result, size, "DIV(%s; %s)", left, right);
    break;
  case 4:
    snprintf(result, size, "MOD(%s; %s)", left, right);
    break;
  }
  free(left);
  free(right);
  return result;
}


x86 assembly (clang, -O0):
<getNewArithmeticOperation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%ecx
mov    %eax,%edx
mov    %ecx,%eax
mov    %edx,%ecx
lea    0x8(%rax,%rcx,1),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %rax,-0x28(%rbp)
sub    $0x4,%rax
ja     1244 <getNewArithmeticOperation+0x104>
mov    -0x28(%rbp),%rax
lea    0xe60(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe55(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1244 <getNewArithmeticOperation+0x104>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe41(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1244 <getNewArithmeticOperation+0x104>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe2d(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1244 <getNewArithmeticOperation+0x104>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe19(%rip),%rdx
call   1050 <snprintf@plt>
jmp    1244 <getNewArithmeticOperation+0x104>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe05(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNewArithmeticOperation>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %eax,%ebp
add    $0x8,%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
cmp    $0x4,%r12d
ja     1196 <getNewArithmeticOperation+0x56>
movslq %r12d,%rax
lea    0xebd(%rip),%rcx
movslq (%rcx,%rax,4),%rdx
add    %rcx,%rdx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %rbx,%rcx
mov    %r14,%r8
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"ADD(%s; %s)\00"
@.str.1 = [12 x i8] c"SUB(%s; %s)\00"
@.str.2 = [12 x i8] c"MUL(%s; %s)\00"
@.str.3 = [12 x i8] c"DIV(%s; %s)\00"
@.str.4 = [12 x i8] c"MOD(%s; %s)\00"
define i8* @getNewArithmeticOperation(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %10, %12
%14 = add nsw i32 %13, 8
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %8
%18 = load i32, i32* %6
switch i32 %18, label %49 [
i32 0, label %19
i32 1, label %25
i32 2, label %31
i32 3, label %37
i32 4, label %43
]
19: ; preds = %3
%20 = load i8*, i8** %8
%21 = load i32, i32* %7
%22 = load i8*, i8** %4
%23 = load i8*, i8** %5
%24 = call i32 @snprintf(i8* %20, i32 %21, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %23)
br label %49
25: ; preds = %3
%26 = load i8*, i8** %8
%27 = load i32, i32* %7
%28 = load i8*, i8** %4
%29 = load i8*, i8** %5
%30 = call i32 @snprintf(i8* %26, i32 %27, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %29)
br label %49
31: ; preds = %3
%32 = load i8*, i8** %8
%33 = load i32, i32* %7
%34 = load i8*, i8** %4
%35 = load i8*, i8** %5
%36 = call i32 @snprintf(i8* %32, i32 %33, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %34, i8* %35)
br label %49
37: ; preds = %3
%38 = load i8*, i8** %8
%39 = load i32, i32* %7
%40 = load i8*, i8** %4
%41 = load i8*, i8** %5
%42 = call i32 @snprintf(i8* %38, i32 %39, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %40, i8* %41)
br label %49
43: ; preds = %3
%44 = load i8*, i8** %8
%45 = load i32, i32* %7
%46 = load i8*, i8** %4
%47 = load i8*, i8** %5
%48 = call i32 @snprintf(i8* %44, i32 %45, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %46, i8* %47)
br label %49
49: ; preds = %3, %43, %37, %31, %25, %19
%50 = load i8*, i8** %4
%51 = call i32 @free(i8* %50)
%52 = load i8*, i8** %5
%53 = call i32 @free(i8* %52)
%54 = load i8*, i8** %8
ret i8* %54
}

LLVM IR (-O2):
@.str = [12 x i8] c"ADD(%s; %s)\00"
@.str.1 = [12 x i8] c"SUB(%s; %s)\00"
@.str.2 = [12 x i8] c"MUL(%s; %s)\00"
@.str.3 = [12 x i8] c"DIV(%s; %s)\00"
@.str.4 = [12 x i8] c"MOD(%s; %s)\00"
@reltable.getNewArithmeticOperation = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str to i64), i64 ptrtoint ([5 x i32]* @reltable.getNewArithmeticOperation to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.1 to i64), i64 ptrtoint ([5 x i32]* @reltable.getNewArithmeticOperation to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.2 to i64), i64 ptrtoint ([5 x i32]* @reltable.getNewArithmeticOperation to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.3 to i64), i64 ptrtoint ([5 x i32]* @reltable.getNewArithmeticOperation to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.4 to i64), i64 ptrtoint ([5 x i32]* @reltable.getNewArithmeticOperation to i64)) to i32)]
define i8* @getNewArithmeticOperation(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = add i32 %4, 8
%7 = add i32 %6, %5
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = icmp ult i32 %2, 5
br i1 %10, label %11, label %16
11: ; preds = %3
%12 = sext i32 %2 to i64
%13 = shl i64 %12, 2
%14 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.getNewArithmeticOperation to i8*), i64 %13)
%15 = tail call i32 @snprintf(i8* %9, i32 %7, i8* %14, i8* %0, i8* %1)
br label %16
16: ; preds = %3, %11
%17 = tail call i32 @free(i8* %0)
%18 = tail call i32 @free(i8* %1)
ret i8* %9
}