#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 *);
scalar_t__ malloc(int);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
void delPath(char *rem) {
  char *path = (char *)malloc((sizeof(char) * strlen(getenv("PATH"))) -
                              (sizeof(char) * strlen(rem)));
  int i = 0;
  char *p;
  for (i = 0, p = strtok(getenv("PATH"), ":"); p != NULL;
       i++, p = strtok(NULL, ":")) {
    if (strcmp(p, rem) == 0) {
      continue;
    } else {
      if (i != 0) {
        strcat(path, ":");
      }
      strcat(path, p);
    }
  }
  setenv("PATH", path, 1);
}


x86 assembly (clang, -O0):
<delPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe7d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
shl    $0x0,%rcx
sub    %rcx,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe2d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
lea    0xe23(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1260 <delPath+0xf0>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1212 <delPath+0xa2>
jmp    123e <delPath+0xce>
cmpl   $0x0,-0x14(%rbp)
je     122c <delPath+0xbc>
mov    -0x10(%rbp),%rdi
lea    0xdde(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <strcat@plt>
jmp    123e <delPath+0xce>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdb3(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    11eb <delPath+0x7b>
mov    -0x10(%rbp),%rsi
lea    0xd95(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delPath>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
lea    0xe7e(%rip),%rbx
mov    %rbx,%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1050 <strlen@plt>
sub    %eax,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <getenv@plt>
lea    0xe4e(%rip),%rsi
mov    %rax,%rdi
call   1080 <strtok@plt>
test   %rax,%rax
je     124a <delPath+0xda>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11e6 <delPath+0x76>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
lea    0xe18(%rip),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
test   %rax,%rax
je     124a <delPath+0xda>
mov    %rax,%rbx
lea    0xe02(%rip),%r12
jmp    1222 <delPath+0xb2>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %edi,%edi
mov    %r12,%rsi
call   1080 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
je     124a <delPath+0xda>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1210 <delPath+0xa0>
mov    %r15,%rdi
mov    %r12,%rsi
call   1090 <strcat@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
jmp    1210 <delPath+0xa0>
lea    0xdaf(%rip),%rdi
mov    %r15,%rsi
mov    $0x1,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <setenv@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"PATH\00"
@.str.1 = [2 x i8] c":\00"
define void @delPath(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @strlen(i8* %6)
%8 = sext i32 %7 to i64
%9 = mul i64 1, %8
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
%12 = sext i32 %11 to i64
%13 = mul i64 1, %12
%14 = sub i64 %9, %13
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %3
store i32 0, i32* %4
store i32 0, i32* %4
%18 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = call i8* @strtok(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %19, i8** %5
br label %20
20: ; preds = %40, %1
%21 = load i8*, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %44
23: ; preds = %20
%24 = load i8*, i8** %5
%25 = load i8*, i8** %2
%26 = call i64 @strcmp(i8* %24, i8* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
br label %40
29: ; preds = %23
%30 = load i32, i32* %4
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i8*, i8** %3
%34 = call i32 @strcat(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %32, %29
%36 = load i8*, i8** %3
%37 = load i8*, i8** %5
%38 = call i32 @strcat(i8* %36, i8* %37)
br label %39
39: ; preds = %35
br label %40
40: ; preds = %39, %28
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
%43 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %43, i8** %5
br label %20
44: ; preds = %20
%45 = load i8*, i8** %3
%46 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %45, i32 1)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"PATH\00"
@.str.1 = [2 x i8] c":\00"
define void @delPath(i8* %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @strlen(i8* %2)
%4 = tail call i32 @strlen(i8* %0)
%5 = sub i32 %3, %4
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = tail call i8* @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %29, label %11
11: ; preds = %1
%12 = tail call i64 @strcmp(i8* %9, i8* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 @strcat(i8* %7, i8* %9)
br label %16
16: ; preds = %14, %11
%17 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %29, label %19
19: ; preds = %16, %26
%20 = phi i8* [ %27, %26 ], [ %17, %16 ]
%21 = tail call i64 @strcmp(i8* %20, i8* %0)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %19
%24 = tail call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = tail call i32 @strcat(i8* %7, i8* %20)
br label %26
26: ; preds = %19, %23
%27 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %19
29: ; preds = %26, %16, %1
%30 = tail call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %7, i32 1)
ret void
}