#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__ ERANGE;
int /*<<< orphan*/ EXIT_FAILURE;
long LONG_MAX;
long LONG_MIN;
int /*<<< orphan*/ _err_exit(char *, int, scalar_t__, char *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
long strtol(char const *, char **, int);
long parse_fd(const char *str) {
  long val;
  char *endptr;
  errno = 0;
  val = strtol(str, &endptr, 10);
  if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) ||
      (errno != 0 && val == 0)) {
    _err_exit("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/Morgan-Stanley/treadmill-pid1/refs/"
              "heads/main/src/pid1.c",
              126, errno, "strtol");
  }
  if (*endptr != '\0') {
    fprintf(stderr, "Invalid filedescriptor number: '%s'\n", str);
    exit(EXIT_FAILURE);
  }
  return val;
}


x86 assembly (clang, -O0):
<parse_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e6d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%rax
mov    0x2e5f(%rip),%rcx
cmp    (%rcx),%rax
jne    11b2 <parse_fd+0x72>
mov    -0x10(%rbp),%rax
mov    0x2e33(%rip),%rcx
cmp    (%rcx),%rax
je     11ce <parse_fd+0x8e>
mov    -0x10(%rbp),%rax
mov    0x2e3f(%rip),%rcx
cmp    (%rcx),%rax
je     11ce <parse_fd+0x8e>
mov    0x2e07(%rip),%rax
cmpq   $0x0,(%rax)
je     11f0 <parse_fd+0xb0>
cmpq   $0x0,-0x10(%rbp)
jne    11f0 <parse_fd+0xb0>
mov    0x2deb(%rip),%rax
mov    (%rax),%rdx
lea    0xe21(%rip),%rdi
mov    $0x7e,%esi
lea    0xea8(%rip),%rcx
call   1030 <_err_exit@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1227 <parse_fd+0xe7>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe86(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_fd>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2e6d(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%rbx
mov    (%r15),%rdx
mov    0x2e6a(%rip),%rax
cmp    (%rax),%rdx
jne    1193 <parse_fd+0x53>
mov    0x2e46(%rip),%rax
cmp    (%rax),%rbx
je     119d <parse_fd+0x5d>
mov    0x2e5a(%rip),%rax
cmp    (%rax),%rbx
je     119d <parse_fd+0x5d>
test   %rdx,%rdx
je     11b5 <parse_fd+0x75>
test   %rbx,%rbx
jne    11b5 <parse_fd+0x75>
lea    0xe5c(%rip),%rdi
lea    0xee8(%rip),%rcx
mov    $0x7e,%esi
call   1030 <_err_exit@plt>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    11cc <parse_fd+0x8c>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xebe(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@.str = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Morgan-Stanley/treadmill-pid1/refs/heads/main/src/pid1.c\00"
@.str.1 = [7 x i8] c"strtol\00"
@stderr = global i32 0
@.str.2 = [37 x i8] c"Invalid filedescriptor number: '%s'\0A\00"
@EXIT_FAILURE = global i32 0
define i64 @parse_fd(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 10)
store i64 %6, i64* %3
%7 = load i64, i64* @errno
%8 = load i64, i64* @ERANGE
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %18
10: ; preds = %1
%11 = load i64, i64* %3
%12 = load i64, i64* @LONG_MAX
%13 = icmp eq i64 %11, %12
br i1 %13, label %24, label %14
14: ; preds = %10
%15 = load i64, i64* %3
%16 = load i64, i64* @LONG_MIN
%17 = icmp eq i64 %15, %16
br i1 %17, label %24, label %18
18: ; preds = %14, %1
%19 = load i64, i64* @errno
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i64, i64* %3
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21, %14, %10
%25 = load i64, i64* @errno
%26 = call i32 @_err_exit(i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str, i64 0, i64 0), i32 126, i64 %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %24, %21, %18
%28 = load i8*, i8** %4
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %2
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %27
%39 = load i64, i64* %3
ret i64 %39
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@.str = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Morgan-Stanley/treadmill-pid1/refs/heads/main/src/pid1.c\00"
@.str.1 = [7 x i8] c"strtol\00"
@stderr = global i32 0
@.str.2 = [37 x i8] c"Invalid filedescriptor number: '%s'\0A\00"
@EXIT_FAILURE = global i32 0
define i64 @parse_fd(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 10)
%5 = load i64, i64* @errno
%6 = load i64, i64* @ERANGE
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i64, i64* @LONG_MAX
%10 = icmp eq i64 %4, %9
%11 = load i64, i64* @LONG_MIN
%12 = icmp eq i64 %4, %11
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %18, label %14
14: ; preds = %8, %1
%15 = icmp ne i64 %5, 0
%16 = icmp eq i64 %4, 0
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %18, label %20
18: ; preds = %14, %8
%19 = tail call i32 @_err_exit(i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str, i64 0, i64 0), i32 126, i64 %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = load i8*, i8** %2
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %20
ret i64 %4
}