#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, ...);
int strlen(char *);
char *gen_assgnmnt(char *code, char *lval, char *rval) {
  char *result;
  if (code) {
    result = (char *)malloc((strlen(code) + strlen(lval) + strlen(rval) + 5) *
                            (sizeof(char)));
    sprintf(result, "%s\t%s = %s\n", code, lval, rval);
  } else {
    result = (char *)malloc((strlen(lval) + strlen(rval) + 5) * (sizeof(char)));
    sprintf(result, "\t%s = %s\n", lval, rval);
  }
  return result;
}


x86 assembly (clang, -O0):
<gen_assgnmnt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11b5 <gen_assgnmnt+0x85>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x5,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    11ff <gen_assgnmnt+0xcf>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0x5,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_assgnmnt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
test   %rdi,%rdi
je     118b <gen_assgnmnt+0x5b>
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %ebp,%ebx
lea    (%rax,%rbx,1),%edi
add    $0x5,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
lea    0xe8a(%rip),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    11c2 <gen_assgnmnt+0x92>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x5,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
lea    0xe50(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [12 x i8] c"%s\09%s = %s\0A\00"
@.str.1 = [10 x i8] c"\09%s = %s\0A\00"
define i8* @gen_assgnmnt(i8* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %15, label %5
5: ; preds = %3
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i32 @strlen(i8* %1)
%8 = tail call i32 @strlen(i8* %2)
%9 = add i32 %6, 5
%10 = add i32 %9, %7
%11 = add i32 %10, %8
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %2)
br label %23
15: ; preds = %3
%16 = tail call i32 @strlen(i8* %1)
%17 = tail call i32 @strlen(i8* %2)
%18 = add i32 %16, 5
%19 = add i32 %18, %17
%20 = tail call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
%22 = tail call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %21, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %2)
br label %23
23: ; preds = %15, %5
%24 = phi i8* [ %13, %5 ], [ %21, %15 ]
ret i8* %24
}