#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
char *getstr();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
char *sconcat(char *, char *);
int main() {
  char *s1, *s2, *s;
  puts("Enter two strings:");
  if (!(s1 = getstr()) || !(s2 = getstr()))
    exit(12);
  printf("Concatenated string is \"%s\".", s = sconcat(s1, s2));
  free(s1);
  free(s2);
  free(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   1070 <getstr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11a5 <main+0x45>
mov    $0x0,%al
call   1070 <getstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11af <main+0x4f>
mov    $0xc,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <sconcat@plt>
mov    %rax,%rsi
mov    %rsi,-0x20(%rbp)
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xe94(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <getstr@plt>
test   %rax,%rax
je     11cc <main+0x6c>
mov    %rax,%r14
xor    %eax,%eax
call   1070 <getstr@plt>
test   %rax,%rax
je     11cc <main+0x6c>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <sconcat@plt>
mov    %rax,%r15
lea    0xe6f(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0xc,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"Enter two strings:\00"
@.str.1 = [29 x i8] c"Concatenated string is \22%s\22.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%6 = call i8* (...) @getstr()
store i8* %6, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i8* (...) @getstr()
store i8* %9, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %8, %0
%12 = call i32 @exit(i32 12)
unreachable
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = load i8*, i8** %3
%16 = call i8* @sconcat(i8* %14, i8* %15)
store i8* %16, i8** %4
%17 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %2
%19 = call i32 @free(i8* %18)
%20 = load i8*, i8** %3
%21 = call i32 @free(i8* %20)
%22 = load i8*, i8** %4
%23 = call i32 @free(i8* %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"Enter two strings:\00"
@.str.1 = [29 x i8] c"Concatenated string is \22%s\22.\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%2 = tail call i8* (...) @getstr()
%3 = icmp eq i8* %2, null
br i1 %3, label %7, label %4
4: ; preds = %0
%5 = tail call i8* (...) @getstr()
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4, %0
%8 = tail call i32 @exit(i32 12)
unreachable
9: ; preds = %4
%10 = tail call i8* @sconcat(i8* %2, i8* %5)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = tail call i32 @free(i8* %2)
%13 = tail call i32 @free(i8* %5)
%14 = tail call i32 @free(i8* %10)
ret i32 0
}