#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__ catf(char **, char *, unsigned int, char *);
int /*<<< orphan*/ free(char *);
char *create_half_a_memory_stage(unsigned inputs, char *write_to,
                                 char *read_from) {
  char *str = NULL;
  unsigned i;
  for (i = 0; i < inputs; ++i) {
    if (catf(&str,
             "        in_%1$d_%2$s <= `in_data(%1$d);\n"
             "        addr_%1$d_%2$s <= `write_addr;\n",
             i, write_to) < 0)
      goto error;
  }
  for (i = 0; i < inputs; ++i) {
    if (catf(&str, "        addr_%1$d_%2$s <= `read_addr(%1$d);\n", i,
             read_from) < 0)
      goto error;
  }
  return str;
error:
  free(str);
  return NULL;
}


x86 assembly (clang, -O0):
<create_half_a_memory_stage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1187 <create_half_a_memory_stage+0x67>
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    -0x28(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1040 <catf@plt>
cmp    $0x0,%rax
jge    1174 <create_half_a_memory_stage+0x54>
jmp    11e0 <create_half_a_memory_stage+0xc0>
jmp    1179 <create_half_a_memory_stage+0x59>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1142 <create_half_a_memory_stage+0x22>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11d3 <create_half_a_memory_stage+0xb3>
mov    -0x2c(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    -0x28(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1040 <catf@plt>
cmp    $0x0,%rax
jge    11c0 <create_half_a_memory_stage+0xa0>
jmp    11e0 <create_half_a_memory_stage+0xc0>
jmp    11c5 <create_half_a_memory_stage+0xa5>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    118e <create_half_a_memory_stage+0x6e>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f1 <create_half_a_memory_stage+0xd1>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_half_a_memory_stage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movq   $0x0,(%rsp)
test   %edi,%edi
je     119d <create_half_a_memory_stage+0x7d>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r15d
xor    %ebp,%ebp
lea    0xeb7(%rip),%r12
mov    %rsp,%r13
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1040 <catf@plt>
test   %rax,%rax
js     11a3 <create_half_a_memory_stage+0x83>
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    1150 <create_half_a_memory_stage+0x30>
test   %r15d,%r15d
je     119d <create_half_a_memory_stage+0x7d>
xor    %ebx,%ebx
lea    0xed5(%rip),%r12
mov    %rsp,%rbp
xchg   %ax,%ax
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
mov    %r14,%rcx
call   1040 <catf@plt>
test   %rax,%rax
js     11a3 <create_half_a_memory_stage+0x83>
add    $0x1,%ebx
cmp    %ebx,%r15d
jne    1180 <create_half_a_memory_stage+0x60>
mov    (%rsp),%rax
jmp    11ae <create_half_a_memory_stage+0x8e>
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [80 x i8] c" in_%1$d_%2$s <= `in_data(%1$d);\0A addr_%1$d_%2$s <= `write_addr;\0A\00"
@.str.1 = [45 x i8] c" addr_%1$d_%2$s <= `read_addr(%1$d);\0A\00"
define i8* @create_half_a_memory_stage(i32 %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* null, i8** %8
store i32 0, i32* %9
br label %10
10: ; preds = %21, %3
%11 = load i32, i32* %9
%12 = load i32, i32* %5
%13 = icmp ult i32 %11, %12
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = load i32, i32* %9
%16 = load i8*, i8** %6
%17 = call i64 @catf(i8** %8, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
br label %41
20: ; preds = %14
br label %21
21: ; preds = %20
%22 = load i32, i32* %9
%23 = add i32 %22, 1
store i32 %23, i32* %9
br label %10
24: ; preds = %10
store i32 0, i32* %9
br label %25
25: ; preds = %36, %24
%26 = load i32, i32* %9
%27 = load i32, i32* %5
%28 = icmp ult i32 %26, %27
br i1 %28, label %29, label %39
29: ; preds = %25
%30 = load i32, i32* %9
%31 = load i8*, i8** %7
%32 = call i64 @catf(i8** %8, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %30, i8* %31)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %29
br label %41
35: ; preds = %29
br label %36
36: ; preds = %35
%37 = load i32, i32* %9
%38 = add i32 %37, 1
store i32 %38, i32* %9
br label %25
39: ; preds = %25
%40 = load i8*, i8** %8
store i8* %40, i8** %4
br label %44
41: ; preds = %34, %19
%42 = load i8*, i8** %8
%43 = call i32 @free(i8* %42)
store i8* null, i8** %4
br label %44
44: ; preds = %41, %39
%45 = load i8*, i8** %4
ret i8* %45
}

LLVM IR (-O2):
@.str = [80 x i8] c" in_%1$d_%2$s <= `in_data(%1$d);\0A addr_%1$d_%2$s <= `write_addr;\0A\00"
@.str.1 = [45 x i8] c" addr_%1$d_%2$s <= `read_addr(%1$d);\0A\00"
define i8* @create_half_a_memory_stage(i32 %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%6 = icmp eq i32 %0, 0
br i1 %6, label %22, label %10
7: ; preds = %10
%8 = icmp eq i32 %14, %0
br i1 %8, label %9, label %10
9: ; preds = %7
br i1 %6, label %22, label %17
10: ; preds = %3, %7
%11 = phi i32 [ %14, %7 ], [ 0, %3 ]
%12 = call i64 @catf(i8** %4, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %1)
%13 = icmp slt i64 %12, 0
%14 = add nuw i32 %11, 1
br i1 %13, label %24, label %7
15: ; preds = %17
%16 = icmp eq i32 %21, %0
br i1 %16, label %22, label %17
17: ; preds = %9, %15
%18 = phi i32 [ %21, %15 ], [ 0, %9 ]
%19 = call i64 @catf(i8** %4, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %18, i8* %2)
%20 = icmp slt i64 %19, 0
%21 = add nuw i32 %18, 1
br i1 %20, label %24, label %15
22: ; preds = %15, %3, %9
%23 = load i8*, i8** %4
br label %27
24: ; preds = %10, %17
%25 = load i8*, i8** %4
%26 = call i32 @free(i8* %25)
br label %27
27: ; preds = %24, %22
%28 = phi i8* [ null, %24 ], [ %23, %22 ]
ret i8* %28
}