#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
char *getenv(char *);
int /*<<< orphan*/ pause();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ setenv(char *, char *, int);
scalar_t__ stat(char *, struct stat *);
int main(int argc, char *argv[]) {
  struct stat stbuf;
  if (argc < 2)
    return -1;
  setenv("XYZ", "11", 1);
  if (stat(argv[1], &stbuf) < 0) {
    perror("stat");
  } else {
    printf("stat successful on %s\n", argv[1]);
  }
  printf("env XYZ = %s\n", getenv("XYZ"));
  pause();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118c <main+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    120d <main+0xad>
lea    0xe6d(%rip),%rdi
lea    0xe6a(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jge    11d0 <main+0x70>
lea    0xe41(%rip),%rdi
call   1080 <perror@plt>
jmp    11e4 <main+0x84>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe2d(%rip),%rdi
call   1050 <printf@plt>
lea    0xe15(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xe29(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <pause@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
cmp    $0x2,%edi
jl     11cd <main+0x6d>
mov    %rsi,%rbx
lea    0xe89(%rip),%rdi
lea    0xe86(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
call   1060 <stat@plt>
test   %rax,%rax
js     11d6 <main+0x76>
mov    0x8(%rbx),%rsi
lea    0xe68(%rip),%rdi
call   1050 <printf@plt>
lea    0xe50(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe67(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <pause@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe2a(%rip),%rdi
call   1080 <perror@plt>
jmp    11a9 <main+0x49>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [4 x i8] c"XYZ\00"
@.str.1 = [3 x i8] c"11\00"
@.str.2 = [5 x i8] c"stat\00"
@.str.3 = [23 x i8] c"stat successful on %s\0A\00"
@.str.4 = [14 x i8] c"env XYZ = %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 -1, i32* %3
br label %28
10: ; preds = %2
%11 = call i32 @setenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 1)
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @stat(i8* %14, %struct.stat* %6)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %24
19: ; preds = %10
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %19, %17
%25 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %25)
%27 = call i32 (...) @pause()
store i32 0, i32* %3
br label %28
28: ; preds = %24, %9
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [4 x i8] c"XYZ\00"
@.str.1 = [3 x i8] c"11\00"
@.str.2 = [5 x i8] c"stat\00"
@.str.3 = [23 x i8] c"stat successful on %s\0A\00"
@.str.4 = [14 x i8] c"env XYZ = %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %21, label %6
6: ; preds = %2
%7 = tail call i32 @setenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 1)
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = call i64 @stat(i8* %9, %struct.stat* %3)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %17
14: ; preds = %6
%15 = load i8*, i8** %8
%16 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %14, %12
%18 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%20 = call i32 (...) @pause()
br label %21
21: ; preds = %2, %17
%22 = phi i32 [ 0, %17 ], [ -1, %2 ]
ret i32 %22
}