#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 */
scalar_t__ errno;
int /*<<< orphan*/ printf(char *, char const *);
int strtol(char const *, char **, int);
int parse_int(const char *str) {
  int res;
  char *end_ptr;
  errno = 0;
  res = strtol(str, &end_ptr, 10);
  if (!errno && *end_ptr == '\0') {
    return res;
  } else {
    errno = 0;
    printf("Invalid test number: %s\n", str);
    return -1;
  }
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ead(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e8a(%rip),%rax
cmpq   $0x0,(%rax)
jne    117b <parse_int+0x5b>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    117b <parse_int+0x5b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a0 <parse_int+0x80>
mov    0x2e5e(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rsi
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eb2(%rip),%r14
movq   $0x0,(%r14)
mov    %rsp,%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
cmpq   $0x0,(%r14)
jne    1151 <parse_int+0x31>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
je     116c <parse_int+0x4c>
movq   $0x0,(%r14)
lea    0xea1(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [25 x i8] c"Invalid test number: %s\0A\00"
define i32 @parse_int(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i64 0, i64* @errno
%6 = load i8*, i8** %3
%7 = call i32 @strtol(i8* %6, i8** %5, i32 10)
store i32 %7, i32* %4
%8 = load i64, i64* @errno
%9 = icmp ne i64 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %1
%11 = load i8*, i8** %5
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = load i32, i32* %4
store i32 %16, i32* %2
br label %20
17: ; preds = %10, %1
store i64 0, i64* @errno
%18 = load i8*, i8** %3
%19 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 -1, i32* %2
br label %20
20: ; preds = %17, %15
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [25 x i8] c"Invalid test number: %s\0A\00"
define i32 @parse_int(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i64 0, i64* @errno
%4 = call i32 @strtol(i8* %0, i8** %2, i32 10)
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %7, %1
store i64 0, i64* @errno
%12 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %7, %11
%14 = phi i32 [ -1, %11 ], [ %4, %7 ]
ret i32 %14
}