#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 *calloc(scalar_t__, int);
char *charalloc(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
scalar_t__ strlen(char *);
char *register_verilog(char *body, char *buf) {
  char *temp = NULL;
  if (body != NULL) {
    temp = charalloc(body);
    free(body);
    body = calloc(strlen(temp) + strlen(buf) + 1, 1);
    sprintf(body, "%s%s", temp, buf);
    free(temp);
  } else {
    body = charalloc(buf);
  }
  return body;
}


x86 assembly (clang, -O0):
<register_verilog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11de <register_verilog+0x8e>
mov    -0x8(%rbp),%rdi
call   1070 <charalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe35(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    11eb <register_verilog+0x9b>
mov    -0x10(%rbp),%rdi
call   1070 <charalloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<register_verilog>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     11be <register_verilog+0x6e>
mov    %rdi,%rbx
call   1070 <charalloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
lea    0xe61(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1060 <sprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <charalloc@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
define i8* @register_verilog(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %5
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %26
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = call i8* @charalloc(i8* %9)
store i8* %10, i8** %5
%11 = load i8*, i8** %3
%12 = call i32 @free(i8* %11)
%13 = load i8*, i8** %5
%14 = call i64 @strlen(i8* %13)
%15 = load i8*, i8** %4
%16 = call i64 @strlen(i8* %15)
%17 = add nsw i64 %14, %16
%18 = add nsw i64 %17, 1
%19 = call i8* @calloc(i64 %18, i32 1)
store i8* %19, i8** %3
%20 = load i8*, i8** %3
%21 = load i8*, i8** %5
%22 = load i8*, i8** %4
%23 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22)
%24 = load i8*, i8** %5
%25 = call i32 @free(i8* %24)
br label %29
26: ; preds = %2
%27 = load i8*, i8** %4
%28 = call i8* @charalloc(i8* %27)
store i8* %28, i8** %3
br label %29
29: ; preds = %26, %8
%30 = load i8*, i8** %3
ret i8* %30
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
define i8* @register_verilog(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %14, label %4
4: ; preds = %2
%5 = tail call i8* @charalloc(i8* %0)
%6 = tail call i32 @free(i8* %0)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%9 = add i64 %7, 1
%10 = add i64 %9, %8
%11 = tail call i8* @calloc(i64 %10, i32 1)
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %1)
%13 = tail call i32 @free(i8* %5)
br label %16
14: ; preds = %2
%15 = tail call i8* @charalloc(i8* %1)
br label %16
16: ; preds = %14, %4
%17 = phi i8* [ %11, %4 ], [ %15, %14 ]
ret i8* %17
}