#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 */
typedef scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ ERANGE;
scalar_t__ errno;
scalar_t__ strtol(char const *, char **, int /*<<< orphan*/);
pid_t parse_pid(const char *pid_str) {
  pid_t pid;
  char *ptr;
  errno = 0;
  pid = (pid_t)strtol(pid_str, &ptr, 0);
  if ((ptr == pid_str) || (*ptr != '\0') || (errno == ERANGE)) {
    pid = 0;
  }
  return pid;
}


x86 assembly (clang, -O0):
<parse_pid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2eb5(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     1175 <parse_pid+0x65>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1175 <parse_pid+0x65>
mov    0x2e76(%rip),%rax
mov    (%rax),%rax
mov    0x2e7c(%rip),%rcx
cmp    (%rcx),%rax
jne    117d <parse_pid+0x6d>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_pid>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eba(%rip),%r14
movq   $0x0,(%r14)
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    (%rsp),%rcx
cmp    %rbx,%rcx
je     114c <parse_pid+0x3c>
cmpb   $0x0,(%rcx)
jne    114c <parse_pid+0x3c>
mov    (%r14),%rcx
mov    0x2ea1(%rip),%rdx
cmp    (%rdx),%rcx
jne    114e <parse_pid+0x3e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
define i64 @parse_pid(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
store i64 0, i64* @errno
%5 = load i8*, i8** %2
%6 = call i64 @strtol(i8* %5, i8** %4, i32 0)
store i64 %6, i64* %3
%7 = load i8*, i8** %4
%8 = load i8*, i8** %2
%9 = icmp eq i8* %7, %8
br i1 %9, label %19, label %10
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = load i64, i64* @errno
%17 = load i64, i64* @ERANGE
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %15, %10, %1
store i64 0, i64* %3
br label %20
20: ; preds = %19, %15
%21 = load i64, i64* %3
ret i64 %21
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
define i64 @parse_pid(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i64 0, i64* @errno
%4 = call i64 @strtol(i8* %0, i8** %2, i32 0)
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, %0
br i1 %6, label %14, label %7
7: ; preds = %1
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i64, i64* @errno
%12 = load i64, i64* @ERANGE
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %10, %7, %1
br label %15
15: ; preds = %14, %10
%16 = phi i64 [ 0, %14 ], [ %4, %10 ]
ret i64 %16
}