#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*/ isdigit(char);
int sscanf(char *, char *, long *);
int read_long(char *ptr, long *val) {
  int nvals;
  while (*ptr != '-' && !isdigit(*ptr) && *ptr != '\0') {
    ptr++;
  }
  nvals = sscanf(ptr, "%ld", val);
  if (nvals != 1) {
    return (0);
  } else {
    return (1);
  }
}


x86 assembly (clang, -O0):
<read_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2d,%ecx
mov    %al,-0x1d(%rbp)
je     1171 <read_long+0x51>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
jne    1171 <read_long+0x51>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1181 <read_long+0x61>
jmp    1192 <read_long+0x72>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1130 <read_long+0x10>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe5f(%rip),%rsi
call   1040 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     11bf <read_long+0x9f>
movl   $0x0,-0x4(%rbp)
jmp    11c6 <read_long+0xa6>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_long>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%al
cmp    $0x2d,%al
je     114d <read_long+0x2d>
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %eax,%eax
jne    114d <read_long+0x2d>
cmpb   $0x0,(%rbx)
je     114d <read_long+0x2d>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
cmp    $0x2d,%al
jne    1130 <read_long+0x10>
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <sscanf@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
sete   %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
define i32 @read_long(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i32
store i8* %0, i8** %4
store i64* %1, i64** %5
br label %7
7: ; preds = %24, %2
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 45
br i1 %11, label %12, label %22
12: ; preds = %7
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = call i32 @isdigit(i8 signext %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br label %22
22: ; preds = %17, %12, %7
%23 = phi i1 [ false, %12 ], [ false, %7 ], [ %21, %17 ]
br i1 %23, label %24, label %27
24: ; preds = %22
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %4
br label %7
27: ; preds = %22
%28 = load i8*, i8** %4
%29 = load i64*, i64** %5
%30 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %29)
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp ne i32 %31, 1
br i1 %32, label %33, label %34
33: ; preds = %27
store i32 0, i32* %3
br label %35
34: ; preds = %27
store i32 1, i32* %3
br label %35
35: ; preds = %34, %33
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
define i32 @read_long(i8* nocapture %0, i64* %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 45
br i1 %4, label %17, label %5
5: ; preds = %2, %13
%6 = phi i8 [ %15, %13 ], [ %3, %2 ]
%7 = phi i8* [ %14, %13 ], [ %0, %2 ]
%8 = tail call i32 @isdigit(i8 signext %6)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %5
%11 = load i8, i8* %7
%12 = icmp eq i8 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %7, i64 1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 45
br i1 %16, label %17, label %5
17: ; preds = %10, %5, %13, %2
%18 = phi i8* [ %0, %2 ], [ %14, %13 ], [ %7, %5 ], [ %7, %10 ]
%19 = tail call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %1)
%20 = icmp eq i32 %19, 1
%21 = zext i1 %20 to i32
ret i32 %21
}