#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*/ EX_USAGE;
int /*<<< orphan*/ dief(int /*<<< orphan*/, char *, ...);
long strtol(char const *, char **, int /*<<< orphan*/);
int parse_id(const char *s) {
  char *end;
  long value;
  value = strtol(s, &end, 0);
  if (!*s || *end) {
    dief(EX_USAGE, "invalid resource id '%s'", s);
  }
  if (value > 0x7fff || value < -0x8000) {
    dief(EX_USAGE,
         "resource id %ld out of range, must be between -32768 and +32767",
         value);
  }
  return value;
}


x86 assembly (clang, -O0):
<parse_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     115c <parse_id+0x3c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1177 <parse_id+0x57>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe90(%rip),%rsi
mov    $0x0,%al
call   1030 <dief@plt>
cmpq   $0x7fff,-0x18(%rbp)
jg     1193 <parse_id+0x73>
cmpq   $0xffffffffffff8000,-0x18(%rbp)
ff
jge    11ae <parse_id+0x8e>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1030 <dief@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_id>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,%r14
cmpb   $0x0,(%rbx)
je     1142 <parse_id+0x22>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     115c <parse_id+0x3c>
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <dief@plt>
movswq %r14w,%rax
cmp    %r14,%rax
je     117f <parse_id+0x5f>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
lea    0xea4(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <dief@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EX_USAGE = global i32 0
@.str = [25 x i8] c"invalid resource id '%s'\00"
@.str.1 = [64 x i8] c"resource id %ld out of range, must be between -32768 and +32767\00"
define i32 @parse_id(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strtol(i8* %5, i8** %3, i32 0)
store i64 %6, i64* %4
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10, %1
%16 = load i32, i32* @EX_USAGE
%17 = load i8*, i8** %2
%18 = call i32 (i32, i8*, ...) @dief(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %15, %10
%20 = load i64, i64* %4
%21 = icmp sgt i64 %20, 32767
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i64, i64* %4
%24 = icmp slt i64 %23, -32768
br i1 %24, label %25, label %29
25: ; preds = %22, %19
%26 = load i32, i32* @EX_USAGE
%27 = load i64, i64* %4
%28 = call i32 (i32, i8*, ...) @dief(i32 %26, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i64 %27)
br label %29
29: ; preds = %25, %22
%30 = load i64, i64* %4
%31 = trunc i64 %30 to i32
ret i32 %31
}

LLVM IR (-O2):
@EX_USAGE = global i32 0
@.str = [25 x i8] c"invalid resource id '%s'\00"
@.str.1 = [64 x i8] c"resource id %ld out of range, must be between -32768 and +32767\00"
define i32 @parse_id(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtol(i8* %0, i8** %2, i32 0)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %7, %1
%12 = load i32, i32* @EX_USAGE
%13 = tail call i32 (i32, i8*, ...) @dief(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %11, %7
%15 = add i64 %4, -32768
%16 = icmp ult i64 %15, -65536
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @EX_USAGE
%19 = tail call i32 (i32, i8*, ...) @dief(i32 %18, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i64 %4)
br label %20
20: ; preds = %14, %17
%21 = trunc i64 %4 to i32
ret i32 %21
}