#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 atoi(char *);
int strlen(char *);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
int parse_pid(char *arg) {
  int pid = 0;
  if ((arg[0] == '0') && (arg[1] == 'x')) {
    if (strlen(arg) > 6)
      return 0;
    pid = (int)strtol(arg + 2, NULL, 16);
  } else {
    if (strlen(arg) > 5)
      return 0;
    pid = atoi(arg);
  }
  return pid;
}


x86 assembly (clang, -O0):
<parse_pid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    11a0 <parse_pid+0x70>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
jne    11a0 <parse_pid+0x70>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x6,%eax
jle    1182 <parse_pid+0x52>
movl   $0x0,-0x4(%rbp)
jmp    11d0 <parse_pid+0xa0>
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,-0x14(%rbp)
jmp    11ca <parse_pid+0x9a>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x5,%eax
jle    11be <parse_pid+0x8e>
movl   $0x0,-0x4(%rbp)
jmp    11d0 <parse_pid+0xa0>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_pid>:
push   %rbx
mov    %rdi,%rbx
cmpb   $0x30,(%rdi)
jne    1165 <parse_pid+0x35>
cmpb   $0x78,0x1(%rbx)
jne    1165 <parse_pid+0x35>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x6,%ecx
jg     1176 <parse_pid+0x46>
add    $0x2,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
jmp    1176 <parse_pid+0x46>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x5,%ecx
jle    1178 <parse_pid+0x48>
pop    %rbx
ret
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <atoi@plt>

LLVM IR (-O0):
define i32 @parse_pid(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%5 = load i8*, i8** %3
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 48
br i1 %9, label %10, label %26
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 120
br i1 %15, label %16, label %26
16: ; preds = %10
%17 = load i8*, i8** %3
%18 = call i32 @strlen(i8* %17)
%19 = icmp sgt i32 %18, 6
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 0, i32* %2
br label %36
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 2
%24 = call i64 @strtol(i8* %23, i32* null, i32 16)
%25 = trunc i64 %24 to i32
store i32 %25, i32* %4
br label %34
26: ; preds = %10, %1
%27 = load i8*, i8** %3
%28 = call i32 @strlen(i8* %27)
%29 = icmp sgt i32 %28, 5
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 0, i32* %2
br label %36
31: ; preds = %26
%32 = load i8*, i8** %3
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %4
br label %34
34: ; preds = %31, %21
%35 = load i32, i32* %4
store i32 %35, i32* %2
br label %36
36: ; preds = %34, %30, %20
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
define i32 @parse_pid(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 48
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 120
br i1 %7, label %8, label %15
8: ; preds = %4
%9 = tail call i32 @strlen(i8* %0)
%10 = icmp sgt i32 %9, 6
br i1 %10, label %20, label %11
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %0, i64 2
%13 = tail call i64 @strtol(i8* nocapture %12, i32* null, i32 16)
%14 = trunc i64 %13 to i32
br label %20
15: ; preds = %4, %1
%16 = tail call i32 @strlen(i8* %0)
%17 = icmp sgt i32 %16, 5
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call i32 @atoi(i8* %0)
br label %20
20: ; preds = %11, %18, %15, %8
%21 = phi i32 [ 0, %8 ], [ 0, %15 ], [ %14, %11 ], [ %19, %18 ]
ret i32 %21
}