#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 */
char *getenv(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ putenv(char *);
scalar_t__ strcmp(char const *, char *);
int test1(void) {
  const char *s;
  if (putenv("foobar=blubb") < 0) {
    printf("test1: putenv 1 failed\n");
    return -1;
  }
  s = getenv("foobar");
  if (s == NULL) {
    printf("test1: getenv 1 failed\n");
    return -1;
  }
  if (strcmp(s, "blubb") != 0) {
    printf("test1: value mismatch\n");
    return -1;
  }
  if (putenv("foobar") < 0) {
    printf("test1: putenv 2 failed\n");
    return -1;
  }
  s = getenv("foobar");
  if (s != NULL) {
    printf("test1: getenv 2 failed\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1050 <putenv@plt>
cmp    $0x0,%rax
jge    1176 <test1+0x36>
lea    0xea8(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1243 <test1+0x103>
lea    0xea8(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a9 <test1+0x69>
lea    0xe94(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1243 <test1+0x103>
mov    -0x10(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11db <test1+0x9b>
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1243 <test1+0x103>
lea    0xe43(%rip),%rdi
call   1050 <putenv@plt>
cmp    $0x0,%rax
jge    1209 <test1+0xc9>
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1243 <test1+0x103>
lea    0xe15(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     123c <test1+0xfc>
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1243 <test1+0x103>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test1>:
push   %rax
lea    0xeb8(%rip),%rdi
call   1050 <putenv@plt>
test   %rax,%rax
js     1180 <test1+0x40>
lea    0xeb4(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1189 <test1+0x49>
lea    0xe9d(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1192 <test1+0x52>
lea    0xec4(%rip),%rdi
jmp    11c4 <test1+0x84>
lea    0xee8(%rip),%rdi
jmp    11c4 <test1+0x84>
lea    0xec8(%rip),%rdi
jmp    11c4 <test1+0x84>
lea    0xe74(%rip),%rdi
call   1050 <putenv@plt>
test   %rax,%rax
js     11bd <test1+0x7d>
lea    0xe63(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11d0 <test1+0x90>
lea    0xe59(%rip),%rdi
jmp    11c4 <test1+0x84>
lea    0xe67(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"foobar=blubb\00"
@.str.1 = [24 x i8] c"test1: putenv 1 failed\0A\00"
@.str.2 = [7 x i8] c"foobar\00"
@.str.3 = [24 x i8] c"test1: getenv 1 failed\0A\00"
@.str.4 = [6 x i8] c"blubb\00"
@.str.5 = [23 x i8] c"test1: value mismatch\0A\00"
@.str.6 = [24 x i8] c"test1: putenv 2 failed\0A\00"
@.str.7 = [24 x i8] c"test1: getenv 2 failed\0A\00"
define i32 @test1() {
%1 = alloca i32
%2 = alloca i8*
%3 = call i64 @putenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %31
7: ; preds = %0
%8 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i8* %8, i8** %2
%9 = load i8*, i8** %2
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %31
13: ; preds = %7
%14 = load i8*, i8** %2
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %31
19: ; preds = %13
%20 = call i64 @putenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %31
24: ; preds = %19
%25 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i8* %25, i8** %2
%26 = load i8*, i8** %2
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %1
br label %31
30: ; preds = %24
store i32 0, i32* %1
br label %31
31: ; preds = %30, %28, %22, %17, %11, %5
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [13 x i8] c"foobar=blubb\00"
@.str.2 = [7 x i8] c"foobar\00"
@.str.4 = [6 x i8] c"blubb\00"
@str = [23 x i8] c"test1: getenv 2 failed\00"
@str.8 = [23 x i8] c"test1: putenv 2 failed\00"
@str.9 = [22 x i8] c"test1: value mismatch\00"
@str.10 = [23 x i8] c"test1: getenv 1 failed\00"
@str.11 = [23 x i8] c"test1: putenv 1 failed\00"
define i32 @test1() {
%1 = tail call i64 @putenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%2 = icmp slt i64 %1, 0
br i1 %2, label %15, label %3
3: ; preds = %0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %15, label %6
6: ; preds = %3
%7 = tail call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %6
%10 = tail call i64 @putenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp slt i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %12, %9, %6, %3, %0
%16 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @str.11, i64 0, i64 0), %0 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @str.10, i64 0, i64 0), %3 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0), %6 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @str.8, i64 0, i64 0), %9 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0), %12 ]
%17 = tail call i32 @puts(i8* dereferenceable(1) %16)
br label %18
18: ; preds = %15, %12
%19 = phi i32 [ 0, %12 ], [ -1, %15 ]
ret i32 %19
}