#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 */
struct session {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ do_format(struct session *, char *);
int /*<<< orphan*/ do_internal_variable(struct session *, char *);
int /*<<< orphan*/ do_showme(struct session *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ substitute(struct session *, char *, char *, int);
struct session *do_echo(struct session *ses, char *arg) {
  char temp[10000];
  sprintf(temp, "result %s", arg);
  do_internal_variable(ses, "result <#echo: error>");
  do_format(ses, temp);
  substitute(ses, "$result", temp, (1 << 1));
  do_showme(ses, temp);
  return ses;
}


x86 assembly (clang, -O0):
<do_echo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2720,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x2720(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe8b(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1070 <do_internal_variable@plt>
mov    -0x8(%rbp),%rdi
lea    -0x2720(%rbp),%rsi
call   1040 <do_format@plt>
mov    -0x8(%rbp),%rdi
lea    -0x2720(%rbp),%rdx
lea    0xe74(%rip),%rsi
mov    $0x2,%ecx
call   1050 <substitute@plt>
mov    -0x8(%rbp),%rdi
lea    -0x2720(%rbp),%rsi
call   1030 <do_showme@plt>
mov    -0x8(%rbp),%rax
add    $0x2720,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_echo>:
push   %r14
push   %rbx
sub    $0x2718,%rsp
mov    %rsi,%rdx
mov    %rdi,%rbx
lea    0xe99(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1060 <sprintf@plt>
lea    0xe91(%rip),%rsi
mov    %rbx,%rdi
call   1070 <do_internal_variable@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <do_format@plt>
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    $0x2,%ecx
call   1050 <substitute@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <do_showme@plt>
mov    %rbx,%rax
add    $0x2718,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.session = type { i32 }
@.str = [10 x i8] c"result %s\00"
@.str.1 = [22 x i8] c"result <#echo: error>\00"
@.str.2 = [8 x i8] c"$result\00"
define %struct.session* @do_echo(%struct.session* %0, i8* %1) {
%3 = alloca %struct.session*
%4 = alloca i8*
%5 = alloca [10000 x i8]
store %struct.session* %0, %struct.session** %3
store i8* %1, i8** %4
%6 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%7 = load i8*, i8** %4
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load %struct.session*, %struct.session** %3
%10 = call i32 @do_internal_variable(%struct.session* %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%11 = load %struct.session*, %struct.session** %3
%12 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%13 = call i32 @do_format(%struct.session* %11, i8* %12)
%14 = load %struct.session*, %struct.session** %3
%15 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%16 = call i32 @substitute(%struct.session* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %15, i32 2)
%17 = load %struct.session*, %struct.session** %3
%18 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%19 = call i32 @do_showme(%struct.session* %17, i8* %18)
%20 = load %struct.session*, %struct.session** %3
ret %struct.session* %20
}

LLVM IR (-O2):
%struct.session = type { i32 }
@.str = [10 x i8] c"result %s\00"
@.str.1 = [22 x i8] c"result <#echo: error>\00"
@.str.2 = [8 x i8] c"$result\00"
define %struct.session* @do_echo(%struct.session* returned %0, i8* %1) {
%3 = alloca [10000 x i8]
%4 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %1)
%6 = tail call i32 @do_internal_variable(%struct.session* %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @do_format(%struct.session* %0, i8* %4)
%8 = call i32 @substitute(%struct.session* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32 2)
%9 = call i32 @do_showme(%struct.session* %0, i8* %4)
ret %struct.session* %0
}