#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*/ printf(char *, ...);
int printenv(int argc, char *argv[]) {
  if (argc != 1) {
    printf("Error: Invalid arguments. setenv does not accept arguments\n");
    return (6);
  }
  extern char **environ;
  int i = 0;
  while (environ[i]) {
    printf("%s\n", environ[i++]);
  }
  return (0);
}


x86 assembly (clang, -O0):
<printenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     1143 <printenv+0x33>
lea    0xed0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x6,-0x4(%rbp)
jmp    1199 <printenv+0x89>
movl   $0x0,-0x14(%rbp)
mov    0x2e97(%rip),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1192 <printenv+0x82>
mov    0x2e7e(%rip),%rax
mov    (%rax),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    114a <printenv+0x3a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printenv>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x1,%edi
jne    1157 <printenv+0x47>
mov    0x2ec8(%rip),%rbx
mov    (%rbx),%rax
mov    (%rax),%rdi
xor    %r14d,%r14d
test   %rdi,%rdi
je     1169 <printenv+0x59>
mov    $0x8,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   1030 <puts@plt>
mov    (%rbx),%rax
mov    (%rax,%rbp,1),%rdi
add    $0x8,%rbp
test   %rdi,%rdi
jne    1140 <printenv+0x30>
jmp    1169 <printenv+0x59>
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
mov    $0x6,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [60 x i8] c"Error: Invalid arguments. setenv does not accept arguments\0A\00"
@environ = external global i8**
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @printenv(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
store i32 6, i32* %3
br label %28
11: ; preds = %2
store i32 0, i32* %6
br label %12
12: ; preds = %19, %11
%13 = load i8**, i8*** @environ
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %27
19: ; preds = %12
%20 = load i8**, i8*** @environ
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i8*, i8** %20, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %25)
br label %12
27: ; preds = %12
store i32 0, i32* %3
br label %28
28: ; preds = %27, %9
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@environ = external global i8**
@str = [59 x i8] c"Error: Invalid arguments. setenv does not accept arguments\00"
define i32 @printenv(i32 %0, i8** nocapture readnone %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i8**, i8*** @environ
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %19, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str, i64 0, i64 0))
br label %19
10: ; preds = %4, %10
%11 = phi i64 [ %13, %10 ], [ 0, %4 ]
%12 = phi i8* [ %17, %10 ], [ %6, %4 ]
%13 = add nuw i64 %11, 1
%14 = tail call i32 @puts(i8* %12)
%15 = load i8**, i8*** @environ
%16 = getelementptr inbounds i8*, i8** %15, i64 %13
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %10
19: ; preds = %10, %4, %8
%20 = phi i32 [ 6, %8 ], [ 0, %4 ], [ 0, %10 ]
ret i32 %20
}