#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 strlen(char const *);
char tolower(char const);
int customer_validate_deliver(const char *str, int *pos, void *arg) {
  const char *s;
  if (strlen(str) > 1) {
    *pos = 1;
    return -1;
  }
  for (s = str; *s; *s++)
    if (tolower(*s) == 'p' || tolower(*s) == 'w' || tolower(*s) == 'v' ||
        tolower(*s) == 'd')
      break;
    else {
      *pos = s - str;
      return -1;
    }
  return 0;
}


x86 assembly (clang, -O0):
<customer_validate_deliver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jle    115c <customer_validate_deliver+0x3c>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11fc <customer_validate_deliver+0xdc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     11f5 <customer_validate_deliver+0xd5>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
cmp    $0x70,%eax
je     11d1 <customer_validate_deliver+0xb1>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
cmp    $0x77,%eax
je     11d1 <customer_validate_deliver+0xb1>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
cmp    $0x76,%eax
je     11d1 <customer_validate_deliver+0xb1>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
cmp    $0x64,%eax
jne    11d6 <customer_validate_deliver+0xb6>
jmp    11f5 <customer_validate_deliver+0xd5>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11fc <customer_validate_deliver+0xdc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<customer_validate_deliver>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    $0x1,%ebp
cmp    $0x1,%eax
jle    1143 <customer_validate_deliver+0x23>
mov    %ebp,(%r14)
mov    $0xffffffff,%ebp
jmp    117d <customer_validate_deliver+0x5d>
mov    (%rbx),%al
xor    %ebp,%ebp
test   %al,%al
je     117d <customer_validate_deliver+0x5d>
movsbl %al,%edi
call   1040 <tolower@plt>
cmp    $0x70,%al
je     117d <customer_validate_deliver+0x5d>
movsbl (%rbx),%edi
call   1040 <tolower@plt>
cmp    $0x77,%al
je     117d <customer_validate_deliver+0x5d>
movsbl (%rbx),%edi
call   1040 <tolower@plt>
cmp    $0x76,%al
je     117d <customer_validate_deliver+0x5d>
movsbl (%rbx),%edi
call   1040 <tolower@plt>
xor    %ebp,%ebp
cmp    $0x64,%al
jne    1139 <customer_validate_deliver+0x19>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @customer_validate_deliver(i8* %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = load i32*, i32** %6
store i32 1, i32* %13
store i32 -1, i32* %4
br label %58
14: ; preds = %3
%15 = load i8*, i8** %5
store i8* %15, i8** %8
br label %16
16: ; preds = %53, %14
%17 = load i8*, i8** %8
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %57
20: ; preds = %16
%21 = load i8*, i8** %8
%22 = load i8, i8* %21
%23 = call signext i8 @tolower(i8 signext %22)
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 112
br i1 %25, label %44, label %26
26: ; preds = %20
%27 = load i8*, i8** %8
%28 = load i8, i8* %27
%29 = call signext i8 @tolower(i8 signext %28)
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 119
br i1 %31, label %44, label %32
32: ; preds = %26
%33 = load i8*, i8** %8
%34 = load i8, i8* %33
%35 = call signext i8 @tolower(i8 signext %34)
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 118
br i1 %37, label %44, label %38
38: ; preds = %32
%39 = load i8*, i8** %8
%40 = load i8, i8* %39
%41 = call signext i8 @tolower(i8 signext %40)
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 100
br i1 %43, label %44, label %45
44: ; preds = %38, %32, %26, %20
br label %57
45: ; preds = %38
%46 = load i8*, i8** %8
%47 = load i8*, i8** %5
%48 = ptrtoint i8* %46 to i64
%49 = ptrtoint i8* %47 to i64
%50 = sub i64 %48, %49
%51 = trunc i64 %50 to i32
%52 = load i32*, i32** %6
store i32 %51, i32* %52
store i32 -1, i32* %4
br label %58
53: ; No predecessors!
%54 = load i8*, i8** %8
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %8
%56 = load i8, i8* %54
br label %16
57: ; preds = %44, %16
store i32 0, i32* %4
br label %58
58: ; preds = %57, %45, %12
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
define i32 @customer_validate_deliver(i8* %0, i32* nocapture writeonly %1, i8* nocapture readnone %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 1
br i1 %5, label %24, label %6
6: ; preds = %3
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %26, label %9
9: ; preds = %6
%10 = tail call signext i8 @tolower(i8 signext %7)
%11 = icmp eq i8 %10, 112
br i1 %11, label %26, label %12
12: ; preds = %9
%13 = load i8, i8* %0
%14 = tail call signext i8 @tolower(i8 signext %13)
%15 = icmp eq i8 %14, 119
br i1 %15, label %26, label %16
16: ; preds = %12
%17 = load i8, i8* %0
%18 = tail call signext i8 @tolower(i8 signext %17)
%19 = icmp eq i8 %18, 118
br i1 %19, label %26, label %20
20: ; preds = %16
%21 = load i8, i8* %0
%22 = tail call signext i8 @tolower(i8 signext %21)
%23 = icmp eq i8 %22, 100
br i1 %23, label %26, label %24
24: ; preds = %20, %3
%25 = phi i32 [ 1, %3 ], [ 0, %20 ]
store i32 %25, i32* %1
br label %26
26: ; preds = %24, %6, %20, %16, %12, %9
%27 = phi i32 [ 0, %9 ], [ 0, %12 ], [ 0, %16 ], [ 0, %20 ], [ 0, %6 ], [ -1, %24 ]
ret i32 %27
}