#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__ is_envp(char *, char **);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[], char *envp[]) {
  int i;
  if (argc == 1) {
    printf("\n");
    return 0;
  }
  for (i = 1; i < argc; i++) {
    if (argv[i][0] == '$') {
      if (is_envp((char *)argv[i] + 1, envp) == 0) {
        printf("%s: Undefined variable\n", (char *)argv[i] + 1);
        return 0;
      }
    } else {
      printf("%s ", argv[i]);
    }
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    115e <main+0x3e>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    121d <main+0xfd>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1208 <main+0xe8>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x24,%eax
jne    11db <main+0xbb>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
call   1040 <is_envp@plt>
cmp    $0x0,%rax
jne    11d6 <main+0xb6>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
add    $0x1,%rsi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    121d <main+0xfd>
jmp    11f5 <main+0xd5>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fa <main+0xda>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1165 <main+0x45>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x1,%edi
je     11aa <main+0x7a>
jle    11aa <main+0x7a>
mov    %rdx,%r14
mov    %rsi,%r13
mov    %edi,%r12d
mov    $0x1,%ebx
lea    0xec3(%rip),%r15
jmp    1173 <main+0x43>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
je     11aa <main+0x7a>
mov    0x0(%r13,%rbx,8),%rsi
cmpb   $0x24,(%rsi)
jne    1160 <main+0x30>
add    $0x1,%rsi
mov    %rsi,%rdi
mov    %r14,%rsi
call   1050 <is_envp@plt>
test   %rax,%rax
jne    116a <main+0x3a>
mov    0x0(%r13,%rbx,8),%rsi
add    $0x1,%rsi
lea    0xe5f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11b4 <main+0x84>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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