#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 */
char *concat(char *, char *);
char *malloc(int);
char *newtemp();
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *, char *);
int strlen(char *);
char *gen_expr(char *first_code, char *second_code, char **lval, char *expr1,
               char *op, char *expr2) {
  char *result = concat(first_code, second_code);
  char *new_code;
  *lval = newtemp();
  new_code =
      malloc((strlen(*lval) + strlen(expr1) + strlen(op) + strlen(expr2) + 7) *
             sizeof(char));
  sprintf(new_code, "\t%s = %s %s %s\n", *lval, expr1, op, expr2);
  result = concat(result, new_code);
  return result;
}


x86 assembly (clang, -O0):
<gen_expr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <concat@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1060 <newtemp@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
add    %ecx,%eax
add    $0x7,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
lea    0xdf7(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <concat@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_expr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r15
mov    %r8,%r14
mov    %rcx,%rbp
mov    %rcx,(%rsp)
mov    %rdx,%rbx
mov    %rdx,0x8(%rsp)
call   1040 <concat@plt>
mov    %rax,0x10(%rsp)
xor    %eax,%eax
call   1060 <newtemp@plt>
mov    %rax,(%rbx)
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %eax,%r13d
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %r14,%rdi
mov    %r14,%rbx
call   1030 <strlen@plt>
mov    %eax,%r14d
mov    %r15,%rdi
call   1030 <strlen@plt>
add    %r13d,%r12d
add    %r14d,%r12d
lea    (%rax,%r12,1),%edi
add    $0x7,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    0x8(%rsp),%rax
mov    (%rax),%rdx
lea    0xe29(%rip),%rsi
mov    %rbp,%rdi
mov    (%rsp),%rcx
mov    %rbx,%r8
mov    %r15,%r9
call   1070 <sprintf@plt>
mov    0x10(%rsp),%rdi
mov    %rbp,%rsi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <concat@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"\09%s = %s %s %s\0A\00"
define i8* @gen_expr(i8* %0, i8* %1, i8** %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8** %2, i8*** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i8* %5, i8** %12
%15 = load i8*, i8** %7
%16 = load i8*, i8** %8
%17 = call i8* @concat(i8* %15, i8* %16)
store i8* %17, i8** %13
%18 = call i8* (...) @newtemp()
%19 = load i8**, i8*** %9
store i8* %18, i8** %19
%20 = load i8**, i8*** %9
%21 = load i8*, i8** %20
%22 = call i32 @strlen(i8* %21)
%23 = load i8*, i8** %10
%24 = call i32 @strlen(i8* %23)
%25 = add nsw i32 %22, %24
%26 = load i8*, i8** %11
%27 = call i32 @strlen(i8* %26)
%28 = add nsw i32 %25, %27
%29 = load i8*, i8** %12
%30 = call i32 @strlen(i8* %29)
%31 = add nsw i32 %28, %30
%32 = add nsw i32 %31, 7
%33 = sext i32 %32 to i64
%34 = mul i64 %33, 1
%35 = trunc i64 %34 to i32
%36 = call i8* @malloc(i32 %35)
store i8* %36, i8** %14
%37 = load i8*, i8** %14
%38 = load i8**, i8*** %9
%39 = load i8*, i8** %38
%40 = load i8*, i8** %10
%41 = load i8*, i8** %11
%42 = load i8*, i8** %12
%43 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %39, i8* %40, i8* %41, i8* %42)
%44 = load i8*, i8** %13
%45 = load i8*, i8** %14
%46 = call i8* @concat(i8* %44, i8* %45)
store i8* %46, i8** %13
%47 = load i8*, i8** %13
ret i8* %47
}

LLVM IR (-O2):
@.str = [16 x i8] c"\09%s = %s %s %s\0A\00"
define i8* @gen_expr(i8* %0, i8* %1, i8** nocapture %2, i8* %3, i8* %4, i8* %5) {
%7 = tail call i8* @concat(i8* %0, i8* %1)
%8 = tail call i8* (...) @newtemp()
store i8* %8, i8** %2
%9 = tail call i32 @strlen(i8* %8)
%10 = tail call i32 @strlen(i8* %3)
%11 = tail call i32 @strlen(i8* %4)
%12 = tail call i32 @strlen(i8* %5)
%13 = add i32 %9, 7
%14 = add i32 %13, %10
%15 = add i32 %14, %11
%16 = add i32 %15, %12
%17 = tail call i8* @malloc(i32 %16)
%18 = load i8*, i8** %2
%19 = tail call i32 @sprintf(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %3, i8* %4, i8* %5)
%20 = tail call i8* @concat(i8* %7, i8* %17)
ret i8* %20
}