#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 */
long LONG_MAX;
long LONG_MIN;
long strtol(char const *, char **, int);
int parse_pid(const char *value, pid_t *pid) {
  long long_val;
  char *end;
  long_val = strtol(value, &end, 10);
  if (*end != '\0' || long_val == LONG_MIN || long_val == LONG_MAX) {
    return -1;
  }
  *pid = (pid_t)long_val;
  return 0;
}


x86 assembly (clang, -O0):
<parse_pid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    116e <parse_pid+0x5e>
mov    -0x20(%rbp),%rax
mov    0x2e97(%rip),%rcx
cmp    (%rcx),%rax
je     116e <parse_pid+0x5e>
mov    -0x20(%rbp),%rax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%rax
jne    117a <parse_pid+0x6a>
movl   $0xffffffff,-0x4(%rbp)
jmp    118c <parse_pid+0x7c>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_pid>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,%rcx
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
mov    $0xffffffff,%eax
jne    1156 <parse_pid+0x46>
mov    0x2ea8(%rip),%rdx
cmp    (%rdx),%rcx
je     1156 <parse_pid+0x46>
mov    0x2e8c(%rip),%rdx
cmp    (%rdx),%rcx
je     1156 <parse_pid+0x46>
mov    %rcx,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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