#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*/ _exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *,
                           unsigned long long, char *);
int /*<<< orphan*/ newenv_exec(char *, char **);
int setenv(char *, char *, int);
int /*<<< orphan*/ stderr;
void test2(void) {
  char *run[4];
  if (setenv("AAAA", "failed", 1) == -1)
    do {
      fprintf(stderr, "%s:%llu: %s\n",
              ("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/janmojzis/tinyssh/refs/heads/"
               "master/tinyssh-tests/newenvtest.c"),
              (unsigned long long)(100), (("setenv failure")));
      fflush(stderr);
      _exit(111);
    } while (0);
  ;
  run[0] = (char *)"/bin/sh";
  run[1] = (char *)"-ec";
  run[2] = (char *)"err='newenvtest2: failed: environment should be empty'\n[ "
                   "x\"$AAAA\" = x ] || ( echo $err; exit 111; ) \nexit 0 \n";
  run[3] = 0;
  newenv_exec(*run, run);
}


x86 assembly (clang, -O0):
<test2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
lea    0xe9f(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
cmp    $0xffffffff,%eax
jne    11be <test2+0x6e>
jmp    117e <test2+0x2e>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
lea    0xe84(%rip),%rdx
mov    $0x64,%ecx
lea    0xf11(%rip),%r8
call   1050 <fprintf@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    $0x6f,%edi
call   1030 <_exit@plt>
lea    0xefc(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xef9(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xef2(%rip),%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x8(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <newenv_exec@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test2>:
push   %rbx
sub    $0x20,%rsp
lea    0xea4(%rip),%rdi
lea    0xea2(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
cmp    $0xffffffff,%eax
je     11ac <test2+0x5c>
lea    0xf48(%rip),%rdi
mov    %rdi,(%rsp)
lea    0xf45(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xf3d(%rip),%rax
mov    %rax,0x10(%rsp)
movq   $0x0,0x18(%rsp)
mov    %rsp,%rsi
call   1070 <newenv_exec@plt>
add    $0x20,%rsp
pop    %rbx
ret
mov    0x2e2d(%rip),%rbx
mov    (%rbx),%edi
lea    0xe50(%rip),%rsi
lea    0xe56(%rip),%rdx
lea    0xee8(%rip),%r8
mov    $0x64,%ecx
call   1050 <fprintf@plt>
mov    (%rbx),%edi
call   1060 <fflush@plt>
mov    $0x6f,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"AAAA\00"
@.str.1 = [7 x i8] c"failed\00"
@stderr = global i32 0
@.str.2 = [13 x i8] c"%s:%llu: %s\0A\00"
@.str.3 = [153 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/janmojzis/tinyssh/refs/heads/master/tinyssh-tests/newenvtest.c\00"
@.str.4 = [15 x i8] c"setenv failure\00"
@.str.5 = [8 x i8] c"/bin/sh\00"
@.str.6 = [4 x i8] c"-ec\00"
@.str.7 = [110 x i8] c"err='newenvtest2: failed: environment should be empty'\0A[ x\22$AAAA\22 = x ] || ( echo $err; exit 111; ) \0Aexit 0 \0A\00"
define void @test2() {
%1 = alloca [4 x i8*]
%2 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %12
4: ; preds = %0
br label %5
5: ; preds = %4
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.3, i64 0, i64 0), i64 100, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%8 = load i32, i32* @stderr
%9 = call i32 @fflush(i32 %8)
%10 = call i32 @_exit(i32 111)
unreachable
11: ; No predecessors!
br label %12
12: ; preds = %11, %0
%13 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8** %14
%15 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 2
store i8* getelementptr inbounds ([110 x i8], [110 x i8]* @.str.7, i64 0, i64 0), i8** %15
%16 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 3
store i8* null, i8** %16
%17 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 0
%18 = load i8*, i8** %17
%19 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 0
%20 = call i32 @newenv_exec(i8* %18, i8** %19)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"AAAA\00"
@.str.1 = [7 x i8] c"failed\00"
@stderr = global i32 0
@.str.2 = [13 x i8] c"%s:%llu: %s\0A\00"
@.str.3 = [153 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/janmojzis/tinyssh/refs/heads/master/tinyssh-tests/newenvtest.c\00"
@.str.4 = [15 x i8] c"setenv failure\00"
@.str.5 = [8 x i8] c"/bin/sh\00"
@.str.6 = [4 x i8] c"-ec\00"
@.str.7 = [110 x i8] c"err='newenvtest2: failed: environment should be empty'\0A[ x\22$AAAA\22 = x ] || ( echo $err; exit 111; ) \0Aexit 0 \0A\00"
define void @test2() {
%1 = alloca [4 x i8*]
%2 = bitcast [4 x i8*]* %1 to i8*
%3 = tail call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %11
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.3, i64 0, i64 0), i64 100, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%8 = load i32, i32* @stderr
%9 = tail call i32 @fflush(i32 %8)
%10 = tail call i32 @_exit(i32 111)
unreachable
11: ; preds = %0
%12 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 2
store i8* getelementptr inbounds ([110 x i8], [110 x i8]* @.str.7, i64 0, i64 0), i8** %14
%15 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 3
store i8* null, i8** %15
%16 = call i32 @newenv_exec(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %12)
ret void
}