#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 */
scalar_t__ malloc(size_t);
int putenv(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
extern int putenv_(char *fchar, int len) {
  char *envstr;
  for (--len; fchar[len] == ' '; len--)
    ;
  if (!(envstr = (char *)malloc((size_t)(++len) + 1)))
    return (-1);
  strncpy(envstr, fchar, len);
  envstr[len] = '\0';
  return (putenv(envstr));
}


x86 assembly (clang, -O0):
<putenv_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    1170 <putenv_+0x40>
jmp    1162 <putenv_+0x32>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1148 <putenv_+0x18>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movslq %eax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    119f <putenv_+0x6f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <putenv_+0x97>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1040 <putenv@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putenv_>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movslq %esi,%rcx
lea    0x1(%rcx),%ebp
lea    (%rcx,%rdi,1),%rax
add    $0xffffffffffffffff,%rax
shl    $0x20,%rcx
movabs $0x100000000,%rbx
add    %rcx,%rbx
movabs $0xffffffff00000000,%rcx
ff ff ff
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %rcx,%rbx
add    $0xffffffff,%ebp
cmpb   $0x20,(%rax)
lea    -0x1(%rax),%rax
je     1170 <putenv_+0x40>
sar    $0x20,%rbx
lea    0x1(%rbx),%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     11b8 <putenv_+0x88>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <putenv@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @putenv_(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = add nsw i32 %7, -1
store i32 %8, i32* %5
br label %9
9: ; preds = %18, %2
%10 = load i8*, i8** %4
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 32
br i1 %16, label %17, label %21
17: ; preds = %9
br label %18
18: ; preds = %17
%19 = load i32, i32* %5
%20 = add nsw i32 %19, -1
store i32 %20, i32* %5
br label %9
21: ; preds = %9
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
%24 = sext i32 %23 to i64
%25 = add i64 %24, 1
%26 = call i64 @malloc(i64 %25)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %21
store i32 -1, i32* %3
br label %41
30: ; preds = %21
%31 = load i8*, i8** %6
%32 = load i8*, i8** %4
%33 = load i32, i32* %5
%34 = call i32 @strncpy(i8* %31, i8* %32, i32 %33)
%35 = load i8*, i8** %6
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 0, i8* %38
%39 = load i8*, i8** %6
%40 = call i32 @putenv(i8* %39)
store i32 %40, i32* %3
br label %41
41: ; preds = %30, %29
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
define i32 @putenv_(i8* %0, i32 %1) {
%3 = sext i32 %1 to i64
br label %4
4: ; preds = %4, %2
%5 = phi i64 [ %6, %4 ], [ %3, %2 ]
%6 = add nsw i64 %5, -1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 32
br i1 %9, label %4, label %10
10: ; preds = %4
%11 = shl i64 %5, 32
%12 = ashr exact i64 %11, 32
%13 = add nsw i64 %12, 1
%14 = tail call i64 @malloc(i64 %13)
%15 = inttoptr i64 %14 to i8*
%16 = icmp eq i64 %14, 0
br i1 %16, label %22, label %17
17: ; preds = %10
%18 = trunc i64 %5 to i32
%19 = tail call i32 @strncpy(i8* %15, i8* %0, i32 %18)
%20 = getelementptr inbounds i8, i8* %15, i64 %12
store i8 0, i8* %20
%21 = tail call i32 @putenv(i8* %15)
br label %22
22: ; preds = %10, %17
%23 = phi i32 [ %21, %17 ], [ -1, %10 ]
ret i32 %23
}