#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 execv(char *, char **);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int main(int argc, char **argv) {
  int idx = 0;
  char envname[50];
  char **newArg;
  if (argc > 1)
    newArg = &argv[1];
  else {
    printf("ERROR: mysetenv must get an application to run as a parameter (e.g "
           "\"./mysetenv /bin/ls\") \n");
    return 1;
  }
  for (idx = 0; idx < 1500; idx++) {
    sprintf(envname, "ZZZ_%d", idx);
    setenv(envname,
           "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
           1);
  }
  return execv(newArg[0], newArg);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1178 <main+0x38>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x58(%rbp)
jmp    1190 <main+0x50>
lea    0xe81(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ed <main+0xad>
movl   $0x0,-0x14(%rbp)
cmpl   $0x5dc,-0x14(%rbp)
jge    11da <main+0x9a>
lea    -0x50(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xea9(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x50(%rbp),%rdi
lea    0xea0(%rip),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1197 <main+0x57>
mov    -0x58(%rbp),%rax
mov    (%rax),%rdi
mov    -0x58(%rbp),%rsi
call   1060 <execv@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
cmp    $0x2,%edi
jl     11aa <main+0x6a>
mov    %rsi,%r14
xor    %ebp,%ebp
lea    0xea3(%rip),%r15
mov    %rsp,%rbx
lea    0xea0(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
add    $0x1,%ebp
cmp    $0x5dc,%ebp
jne    1170 <main+0x30>
mov    0x8(%r14),%rdi
add    $0x8,%r14
mov    %r14,%rsi
call   1060 <execv@plt>
jmp    11bb <main+0x7b>
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [91 x i8] c"ERROR: mysetenv must get an application to run as a parameter (e.g \22./mysetenv /bin/ls\22) \0A\00"
@.str.1 = [7 x i8] c"ZZZ_%d\00"
@.str.2 = [65 x i8] c"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [50 x i8]
%8 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
store i8** %13, i8*** %8
br label %16
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %35
16: ; preds = %11
store i32 0, i32* %6
br label %17
17: ; preds = %26, %16
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 1500
br i1 %19, label %20, label %29
20: ; preds = %17
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%22 = load i32, i32* %6
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%25 = call i32 @setenv(i8* %24, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %26
26: ; preds = %20
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %17
29: ; preds = %17
%30 = load i8**, i8*** %8
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %8
%34 = call i32 @execv(i8* %32, i8** %33)
store i32 %34, i32* %3
br label %35
35: ; preds = %29, %14
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"ZZZ_%d\00"
@.str.2 = [65 x i8] c"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\00"
@str = [90 x i8] c"ERROR: mysetenv must get an application to run as a parameter (e.g \22./mysetenv /bin/ls\22) \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [50 x i8]
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([90 x i8], [90 x i8]* @str, i64 0, i64 0))
br label %18
8: ; preds = %2, %8
%9 = phi i32 [ %12, %8 ], [ 0, %2 ]
%10 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = call i32 @setenv(i8* %4, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0), i32 1)
%12 = add nuw nsw i32 %9, 1
%13 = icmp eq i32 %12, 1500
br i1 %13, label %14, label %8
14: ; preds = %8
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @execv(i8* %16, i8** %15)
br label %18
18: ; preds = %14, %6
%19 = phi i32 [ %17, %14 ], [ 1, %6 ]
ret i32 %19
}