#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*/ assert(char const *);
long strtol(char const *, char **, int);
int get_filedes(const char *txt) {
  long fd;
  char *endbuf;
  assert(txt);
  if (txt[0] == '-' && txt[1] == 0)
    return -2;
  fd = strtol(txt, &endbuf, 10);
  if (endbuf == txt || *endbuf != 0)
    return -1;
  return fd;
}


x86 assembly (clang, -O0):
<get_filedes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1162 <get_filedes+0x42>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1162 <get_filedes+0x42>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11a9 <get_filedes+0x89>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1196 <get_filedes+0x76>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a2 <get_filedes+0x82>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <get_filedes+0x89>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_filedes>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1030 <assert@plt>
cmpb   $0x2d,(%rbx)
jne    1138 <get_filedes+0x18>
cmpb   $0x0,0x1(%rbx)
je     1165 <get_filedes+0x45>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    0x8(%rsp),%rcx
cmp    %rbx,%rcx
je     115e <get_filedes+0x3e>
xor    %edx,%edx
cmp    (%rcx),%dl
sbb    %ecx,%ecx
or     %eax,%ecx
jmp    116a <get_filedes+0x4a>
mov    $0xffffffff,%ecx
jmp    116a <get_filedes+0x4a>
mov    $0xfffffffe,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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