#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 *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int echo(char *args[], int size) {
  int i;
  char *value;
  if (size == 0) {
    puts("");
    return 1;
  }
  for (i = 0; i < size; i++) {
    if (args[i][0] == '$') {
      value = getenv(args[i] + 1);
      printf("%s", value);
    } else
      printf("%s", args[i]);
    if (i != size - 1)
      printf(" ");
    else
      printf("\n");
  }
  return 1;
}


x86 assembly (clang, -O0):
<echo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1161 <echo+0x31>
lea    0xeb6(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1222 <echo+0xf2>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    121b <echo+0xeb>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x24,%eax
jne    11bc <echo+0x8c>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
add    $0x1,%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11d6 <echo+0xa6>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     11fa <echo+0xca>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1208 <echo+0xd8>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    120d <echo+0xdd>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1168 <echo+0x38>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<echo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     11a1 <echo+0x71>
jle    11ab <echo+0x7b>
mov    %rdi,%r15
lea    -0x1(%rsi),%r12d
mov    %esi,%ebx
lea    0xeaf(%rip),%r14
mov    $0xa,%r13d
xor    %ebp,%ebp
jmp    1184 <echo+0x54>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %rbp,%r12
mov    $0x20,%edi
cmove  %r13d,%edi
call   1040 <putchar@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
je     11ab <echo+0x7b>
mov    (%r15,%rbp,8),%rsi
cmpb   $0x24,(%rsi)
jne    1160 <echo+0x30>
add    $0x1,%rsi
mov    %rsi,%rdi
call   1030 <getenv@plt>
mov    %r14,%rdi
mov    %rax,%rsi
jmp    1163 <echo+0x33>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @echo(i8** %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8** %0, i8*** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %58
12: ; preds = %2
store i32 0, i32* %6
br label %13
13: ; preds = %54, %12
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %57
17: ; preds = %13
%18 = load i8**, i8*** %4
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 36
br i1 %26, label %27, label %37
27: ; preds = %17
%28 = load i8**, i8*** %4
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = call i8* @getenv(i8* %33)
store i8* %34, i8** %7
%35 = load i8*, i8** %7
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %35)
br label %44
37: ; preds = %17
%38 = load i8**, i8*** %4
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %37, %27
%45 = load i32, i32* %6
%46 = load i32, i32* %5
%47 = sub nsw i32 %46, 1
%48 = icmp ne i32 %45, %47
br i1 %48, label %49, label %51
49: ; preds = %44
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %53
51: ; preds = %44
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %53
53: ; preds = %51, %49
br label %54
54: ; preds = %53
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
br label %13
57: ; preds = %13
store i32 1, i32* %3
br label %58
58: ; preds = %57, %10
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
define i32 @echo(i8** nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %30
6: ; preds = %4
%7 = add nsw i32 %1, -1
%8 = zext i32 %7 to i64
%9 = zext i32 %1 to i64
br label %12
10: ; preds = %2
%11 = tail call i32 @putchar(i32 10)
br label %30
12: ; preds = %6, %24
%13 = phi i64 [ 0, %6 ], [ %28, %24 ]
%14 = getelementptr inbounds i8*, i8** %0, i64 %13
%15 = load i8*, i8** %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 36
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = getelementptr inbounds i8, i8* %15, i64 1
%20 = tail call i8* @getenv(i8* %19)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %24
22: ; preds = %12
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %24
24: ; preds = %22, %18
%25 = icmp eq i64 %13, %8
%26 = select i1 %25, i32 10, i32 32
%27 = tail call i32 @putchar(i32 %26)
%28 = add nuw nsw i64 %13, 1
%29 = icmp eq i64 %28, %9
br i1 %29, label %30, label %12
30: ; preds = %24, %4, %10
ret i32 1
}