#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*/ abort();
int /*<<< orphan*/ getenv(char const *);
int /*<<< orphan*/ log_oom(char *, int, char *);
char *malloc(int);
int putenv(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
extern int unsetenv(const char *name) {
  int len, rc;
  char *tmp;
  if (!getenv(name))
    return 0;
  len = strlen(name);
  tmp = malloc(len + 3);
  if (!tmp) {
    log_oom("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/Q-Leap-Networks/debian-slurm/refs/heads/"
            "master/slurm/src/common/unsetenv.c",
            56, "");
    abort();
  }
  strcpy(tmp, name);
  strcat(tmp, "=x");
  if ((rc = putenv(tmp)) != 0)
    return rc;
  tmp[0] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<unsetenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%eax
jne    11aa <unsetenv+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    123a <unsetenv+0xba>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x3,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ef <unsetenv+0x6f>
lea    0xe29(%rip),%rdi
mov    $0x38,%esi
lea    0xec1(%rip),%rdx
call   1080 <log_oom@plt>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   1070 <putenv@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     122c <unsetenv+0xac>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    123a <unsetenv+0xba>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unsetenv>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <getenv@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
je     11d7 <unsetenv+0x57>
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    0x3(%rax),%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     11df <unsetenv+0x5f>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
lea    0xee7(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
call   1070 <putenv@plt>
test   %eax,%eax
jne    11d7 <unsetenv+0x57>
movb   $0x0,(%rbx)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe1a(%rip),%rdi
lea    0xeb7(%rip),%rdx
mov    $0x38,%esi
call   1080 <log_oom@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@.str = [165 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Q-Leap-Networks/debian-slurm/refs/heads/master/slurm/src/common/unsetenv.c\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [3 x i8] c"=x\00"
define i32 @unsetenv(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @getenv(i8* %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %1
store i32 0, i32* %2
br label %36
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 3
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %11
%20 = call i32 @log_oom(i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str, i64 0, i64 0), i32 56, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 (...) @abort()
unreachable
22: ; preds = %11
%23 = load i8*, i8** %6
%24 = load i8*, i8** %3
%25 = call i32 @strcpy(i8* %23, i8* %24)
%26 = load i8*, i8** %6
%27 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%28 = load i8*, i8** %6
%29 = call i32 @putenv(i8* %28)
store i32 %29, i32* %5
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %22
%32 = load i32, i32* %5
store i32 %32, i32* %2
br label %36
33: ; preds = %22
%34 = load i8*, i8** %6
%35 = getelementptr inbounds i8, i8* %34, i64 0
store i8 0, i8* %35
store i32 0, i32* %2
br label %36
36: ; preds = %33, %31, %10
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@.str = [165 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Q-Leap-Networks/debian-slurm/refs/heads/master/slurm/src/common/unsetenv.c\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [3 x i8] c"=x\00"
define i32 @unsetenv(i8* %0) {
%2 = tail call i32 @getenv(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %18, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, 3
%7 = tail call i8* @malloc(i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = tail call i32 @log_oom(i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str, i64 0, i64 0), i32 56, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 (...) @abort()
unreachable
12: ; preds = %4
%13 = tail call i32 @strcpy(i8* %7, i8* %0)
%14 = tail call i32 @strcat(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @putenv(i8* %7)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
store i8 0, i8* %7
br label %18
18: ; preds = %12, %1, %17
%19 = phi i32 [ 0, %17 ], [ 0, %1 ], [ %15, %12 ]
ret i32 %19
}