#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 *__readString(char *);
int /*<<< orphan*/ asprintf(char **, char *, char *, char *);
int /*<<< orphan*/ free(char *);
char *readId() {
  char *ret, *tmp, *t;
  tmp = __readString("prod_id1");
  ret = tmp;
  tmp = __readString("prod_id2");
  if (!tmp)
    return ret;
  asprintf(&t, "%s %s", ret, tmp);
  free(ret);
  ret = t;
  tmp = __readString("prod_id3");
  if (!tmp)
    return ret;
  asprintf(&t, "%s %s", ret, tmp);
  free(ret);
  ret = t;
  tmp = __readString("prod_id4");
  if (!tmp)
    return ret;
  asprintf(&t, "%s %s", ret, tmp);
  free(ret);
  ret = t;
  return ret;
}


x86 assembly (clang, -O0):
<readId>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
call   1050 <__readString@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0xeb2(%rip),%rdi
call   1050 <__readString@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1178 <readId+0x48>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    124b <readId+0x11b>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1040 <asprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0xe70(%rip),%rdi
call   1050 <__readString@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c9 <readId+0x99>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    124b <readId+0x11b>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1040 <asprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0xe28(%rip),%rdi
call   1050 <__readString@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121a <readId+0xea>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    124b <readId+0x11b>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   1040 <asprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readId>:
push   %rbx
sub    $0x10,%rsp
lea    0xec4(%rip),%rdi
call   1050 <__readString@plt>
mov    %rax,%rbx
lea    0xebe(%rip),%rdi
call   1050 <__readString@plt>
test   %rax,%rax
je     11e7 <readId+0xb7>
lea    0xeb2(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <asprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rbx
lea    0xe94(%rip),%rdi
call   1050 <__readString@plt>
test   %rax,%rax
je     11e7 <readId+0xb7>
lea    0xe7d(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <asprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rbx
lea    0xe68(%rip),%rdi
call   1050 <__readString@plt>
test   %rax,%rax
je     11e7 <readId+0xb7>
lea    0xe48(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <asprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"prod_id1\00"
@.str.1 = [9 x i8] c"prod_id2\00"
@.str.2 = [6 x i8] c"%s %s\00"
@.str.3 = [9 x i8] c"prod_id3\00"
@.str.4 = [9 x i8] c"prod_id4\00"
define i8* @readId() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = call i8* @__readString(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %3
%6 = load i8*, i8** %3
store i8* %6, i8** %2
%7 = call i8* @__readString(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = load i8*, i8** %2
store i8* %11, i8** %1
br label %44
12: ; preds = %0
%13 = load i8*, i8** %2
%14 = load i8*, i8** %3
%15 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %13, i8* %14)
%16 = load i8*, i8** %2
%17 = call i32 @free(i8* %16)
%18 = load i8*, i8** %4
store i8* %18, i8** %2
%19 = call i8* @__readString(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i8* %19, i8** %3
%20 = load i8*, i8** %3
%21 = icmp ne i8* %20, null
br i1 %21, label %24, label %22
22: ; preds = %12
%23 = load i8*, i8** %2
store i8* %23, i8** %1
br label %44
24: ; preds = %12
%25 = load i8*, i8** %2
%26 = load i8*, i8** %3
%27 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %25, i8* %26)
%28 = load i8*, i8** %2
%29 = call i32 @free(i8* %28)
%30 = load i8*, i8** %4
store i8* %30, i8** %2
%31 = call i8* @__readString(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
store i8* %31, i8** %3
%32 = load i8*, i8** %3
%33 = icmp ne i8* %32, null
br i1 %33, label %36, label %34
34: ; preds = %24
%35 = load i8*, i8** %2
store i8* %35, i8** %1
br label %44
36: ; preds = %24
%37 = load i8*, i8** %2
%38 = load i8*, i8** %3
%39 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %37, i8* %38)
%40 = load i8*, i8** %2
%41 = call i32 @free(i8* %40)
%42 = load i8*, i8** %4
store i8* %42, i8** %2
%43 = load i8*, i8** %2
store i8* %43, i8** %1
br label %44
44: ; preds = %36, %34, %22, %10
%45 = load i8*, i8** %1
ret i8* %45
}

LLVM IR (-O2):
@.str = [9 x i8] c"prod_id1\00"
@.str.1 = [9 x i8] c"prod_id2\00"
@.str.2 = [6 x i8] c"%s %s\00"
@.str.3 = [9 x i8] c"prod_id3\00"
@.str.4 = [9 x i8] c"prod_id4\00"
define i8* @readId() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = tail call i8* @__readString(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @__readString(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %22, label %6
6: ; preds = %0
%7 = call i32 @asprintf(i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %3, i8* %4)
%8 = call i32 @free(i8* %3)
%9 = load i8*, i8** %1
%10 = call i8* @__readString(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %22, label %12
12: ; preds = %6
%13 = call i32 @asprintf(i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %9, i8* %10)
%14 = call i32 @free(i8* %9)
%15 = load i8*, i8** %1
%16 = call i8* @__readString(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %22, label %18
18: ; preds = %12
%19 = call i32 @asprintf(i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %15, i8* %16)
%20 = call i32 @free(i8* %15)
%21 = load i8*, i8** %1
br label %22
22: ; preds = %12, %6, %0, %18
%23 = phi i8* [ %21, %18 ], [ %3, %0 ], [ %9, %6 ], [ %15, %12 ]
ret i8* %23
}