#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*/ exit_func(char *);
scalar_t__ my_strncmp(char *, char *, int);
int find_pwd(char **envp) {
  int i;
  i = 0;
  while (envp[i]) {
    if (my_strncmp(envp[i], "PWD", 3) == 0)
      return (i);
    ++i;
  }
  exit_func("Error: PWD doesn't exist in PATH.\n");
  return (0);
}


x86 assembly (clang, -O0):
<find_pwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1186 <find_pwd+0x66>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xea7(%rip),%rsi
mov    $0x3,%edx
call   1030 <my_strncmp@plt>
cmp    $0x0,%rax
jne    1178 <find_pwd+0x58>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1199 <find_pwd+0x79>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1133 <find_pwd+0x13>
lea    0xe77(%rip),%rdi
call   1040 <exit_func@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_pwd>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1160 <find_pwd+0x40>
xor    %ebx,%ebx
lea    0xec7(%rip),%r15
nopl   0x0(%rax)
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <my_strncmp@plt>
test   %rax,%rax
je     116e <find_pwd+0x4e>
mov    0x8(%r14,%rbx,8),%rdi
add    $0x1,%rbx
test   %rdi,%rdi
jne    1140 <find_pwd+0x20>
lea    0xe9d(%rip),%rdi
call   1040 <exit_func@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"PWD\00"
@.str.1 = [35 x i8] c"Error: PWD doesn't exist in PATH.\0A\00"
define i32 @find_pwd(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
store i8** %0, i8*** %3
store i32 0, i32* %4
br label %5
5: ; preds = %22, %1
%6 = load i8**, i8*** %3
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8*, i8** %6, i64 %8
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %25
12: ; preds = %5
%13 = load i8**, i8*** %3
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = call i64 @my_strncmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = load i32, i32* %4
store i32 %21, i32* %2
br label %27
22: ; preds = %12
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %5
25: ; preds = %5
%26 = call i32 @exit_func(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %27
27: ; preds = %25, %20
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [4 x i8] c"PWD\00"
@.str.1 = [35 x i8] c"Error: PWD doesn't exist in PATH.\0A\00"
define i32 @find_pwd(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = icmp eq i8* %2, null
br i1 %3, label %14, label %4
4: ; preds = %1, %9
%5 = phi i64 [ %10, %9 ], [ 0, %1 ]
%6 = phi i8* [ %12, %9 ], [ %2, %1 ]
%7 = tail call i64 @my_strncmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %4
%10 = add nuw i64 %5, 1
%11 = getelementptr inbounds i8*, i8** %0, i64 %10
%12 = load i8*, i8** %11
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %4
14: ; preds = %9, %1
%15 = tail call i32 @exit_func(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %18
16: ; preds = %4
%17 = trunc i64 %5 to i32
br label %18
18: ; preds = %16, %14
%19 = phi i32 [ 0, %14 ], [ %17, %16 ]
ret i32 %19
}