#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*/ sprintf(char *, char *, char const *const, ...);
void get_env_cmd(char *line, char const *const *args, char const *pager) {
  if (args[1] == NULL) {
    sprintf(line, "printenv | sort | %s", pager);
  } else {
    sprintf(line, "printenv | sort | grep %s | %s", args[1], pager);
  }
}


x86 assembly (clang, -O0):
<get_env_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    114e <get_env_cmd+0x3e>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xebe(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    116c <get_env_cmd+0x5c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x18(%rbp),%rcx
lea    0xeb0(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_env_cmd>:
mov    %rdx,%rcx
mov    0x8(%rsi),%rdx
test   %rdx,%rdx
je     112a <get_env_cmd+0x1a>
lea    0xef2(%rip),%rsi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
lea    0xecf(%rip),%rsi
mov    %rcx,%rdx
xor    %eax,%eax
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"printenv | sort | %s\00"
@.str.1 = [31 x i8] c"printenv | sort | grep %s | %s\00"
define void @get_env_cmd(i8* %0, i8** %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = load i8*, i8** %6
%14 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %22
15: ; preds = %3
%16 = load i8*, i8** %4
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i8*, i8** %6
%21 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %20)
br label %22
22: ; preds = %15, %11
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"printenv | sort | %s\00"
@.str.1 = [31 x i8] c"printenv | sort | grep %s | %s\00"
define void @get_env_cmd(i8* nocapture writeonly %0, i8** nocapture %1, i8* %2) {
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %11
9: ; preds = %3
%10 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %2)
br label %11
11: ; preds = %9, %7
ret void
}