#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 exec_cmdline(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ get_env_cmd(char *, char const *const *, char *);
char *getenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
void check_env(char const *const *args) {
  char line[(1023) + 1], pager[(1023) + 1];
  int no_cmds = (args[1] == NULL ? 3 : 4);
  if (getenv("PAGER") != NULL) {
    sprintf(pager, "%s", getenv("PAGER"));
  } else {
    sprintf(pager, "less");
  }
  get_env_cmd(line, args, pager);
  fprintf(stdout, "Actual command line: %s\n", line);
  if (exec_cmdline(line) == no_cmds && strcmp(pager, "less") == 0) {
    get_env_cmd(line, args, "more");
    fprintf(stdout, "Actual command line: %s\n", line);
    exec_cmdline(line);
  }
}


x86 assembly (clang, -O0):
<check_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdx
mov    $0x4,%eax
mov    $0x3,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x814(%rbp)
lea    0xe6b(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     11db <check_env+0x7b>
lea    -0x810(%rbp),%rax
mov    %rax,-0x820(%rbp)
lea    0xe47(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x820(%rbp),%rdi
mov    %rax,%rdx
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
jmp    11f0 <check_env+0x90>
lea    -0x810(%rbp),%rdi
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x810(%rbp),%rdx
call   1040 <get_env_cmd@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xdf0(%rip),%rsi
call   1060 <fprintf@plt>
lea    -0x410(%rbp),%rdi
call   1070 <exec_cmdline@plt>
cmp    -0x814(%rbp),%eax
jne    1297 <check_env+0x137>
lea    -0x810(%rbp),%rdi
lea    0xdc0(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1297 <check_env+0x137>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    0xdbd(%rip),%rdx
call   1040 <get_env_cmd@plt>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xd88(%rip),%rsi
call   1060 <fprintf@plt>
lea    -0x410(%rbp),%rdi
call   1070 <exec_cmdline@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_env>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %rdi,%r14
cmpq   $0x1,0x8(%rdi)
mov    $0x4,%ebp
sbb    $0x0,%ebp
lea    0xe7c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     119b <check_env+0x3b>
mov    %rsp,%rdi
mov    %rax,%rsi
call   1050 <strcpy@plt>
jmp    11a7 <check_env+0x47>
movb   $0x0,0x4(%rsp)
movl   $0x7373656c,(%rsp)
lea    0x400(%rsp),%rbx
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <get_env_cmd@plt>
mov    0x2e1c(%rip),%r15
mov    (%r15),%edi
lea    0xe3d(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <exec_cmdline@plt>
cmp    %ebp,%eax
jne    122a <check_env+0xca>
lea    0xe1d(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    122a <check_env+0xca>
lea    0xe27(%rip),%rdx
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <get_env_cmd@plt>
mov    (%r15),%edi
lea    0xdf1(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <exec_cmdline@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"PAGER\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c"less\00"
@stdout = global i32 0
@.str.3 = [25 x i8] c"Actual command line: %s\0A\00"
@.str.4 = [5 x i8] c"more\00"
define void @check_env(i8** %0) {
%2 = alloca i8**
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca i32
store i8** %0, i8*** %2
%6 = load i8**, i8*** %2
%7 = getelementptr inbounds i8*, i8** %6, i64 1
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
%10 = zext i1 %9 to i64
%11 = select i1 %9, i32 3, i32 4
store i32 %11, i32* %5
%12 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%16 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %21
18: ; preds = %1
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%20 = call i32 (i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %18, %14
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%23 = load i8**, i8*** %2
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%25 = call i32 @get_env_cmd(i8* %22, i8** %23, i8* %24)
%26 = load i32, i32* @stdout
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%30 = call i32 @exec_cmdline(i8* %29)
%31 = load i32, i32* %5
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %46
33: ; preds = %21
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %33
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%39 = load i8**, i8*** %2
%40 = call i32 @get_env_cmd(i8* %38, i8** %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%41 = load i32, i32* @stdout
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %42)
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%45 = call i32 @exec_cmdline(i8* %44)
br label %46
46: ; preds = %37, %33, %21
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"PAGER\00"
@.str.2 = [5 x i8] c"less\00"
@stdout = global i32 0
@.str.3 = [25 x i8] c"Actual command line: %s\0A\00"
@.str.4 = [5 x i8] c"more\00"
define void @check_env(i8** %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds i8*, i8** %0, i64 1
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
%9 = select i1 %8, i32 3, i32 4
%10 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %1
%13 = call i8* @strcpy(i8* %5, i8* %10)
br label %15
14: ; preds = %1
br label %15
15: ; preds = %14, %12
%16 = call i32 @get_env_cmd(i8* %4, i8** %0, i8* %5)
%17 = load i32, i32* @stdout
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%19 = call i32 @exec_cmdline(i8* %4)
%20 = icmp eq i32 %19, %9
br i1 %20, label %21, label %29
21: ; preds = %15
%22 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = call i32 @get_env_cmd(i8* %4, i8** %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%26 = load i32, i32* @stdout
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%28 = call i32 @exec_cmdline(i8* %4)
br label %29
29: ; preds = %24, %21, %15
ret void
}