#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 */
typedef scalar_t__ id_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, char const *);
scalar_t__ errno;
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *, char const *, char const *);
scalar_t__ strtoul(char const *, char **, int);
id_t id(const char *name, const char *type) {
  id_t val;
  char *ep;
  errno = 0;
  if (*name == '#')
    name++;
  val = (id_t)strtoul(name, &ep, 10);
  if (errno)
    err(EXIT_FAILURE, "%s", name);
  if (*ep != '\0')
    errx(EXIT_FAILURE, "%s: invalid %s name", name, type);
  return (val);
}


x86 assembly (clang, -O0):
<id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e99(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    116a <id+0x3a>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e59(%rip),%rax
cmpq   $0x0,(%rax)
je     11aa <id+0x7a>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe5b(%rip),%rsi
call   1040 <err@plt>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d7 <id+0xa7>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe31(%rip),%rsi
call   1030 <errx@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<id>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2e9e(%rip),%r12
movq   $0x0,(%r12)
xor    %ebx,%ebx
cmpb   $0x23,(%rdi)
sete   %bl
add    %rdi,%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %rax,%r15
cmpq   $0x0,(%r12)
je     1187 <id+0x57>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
mov    %rbx,%rdx
call   1040 <err@plt>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     11ab <id+0x7b>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <errx@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@EXIT_FAILURE = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [20 x i8] c"%s: invalid %s name\00"
define i64 @id(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i64 0, i64* @errno
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 35
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %3
br label %14
14: ; preds = %11, %2
%15 = load i8*, i8** %3
%16 = call i64 @strtoul(i8* %15, i8** %6, i32 10)
store i64 %16, i64* %5
%17 = load i64, i64* @errno
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i32, i32* @EXIT_FAILURE
%21 = load i8*, i8** %3
%22 = call i32 @err(i32 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %19, %14
%24 = load i8*, i8** %6
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %23
%29 = load i32, i32* @EXIT_FAILURE
%30 = load i8*, i8** %3
%31 = load i8*, i8** %4
%32 = call i32 @errx(i32 %29, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %31)
br label %33
33: ; preds = %28, %23
%34 = load i64, i64* %5
ret i64 %34
}

LLVM IR (-O2):
@errno = global i64 0
@EXIT_FAILURE = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [20 x i8] c"%s: invalid %s name\00"
define i64 @id(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 35
%7 = zext i1 %6 to i64
%8 = getelementptr i8, i8* %0, i64 %7
%9 = call i64 @strtoul(i8* %8, i8** %3, i32 10)
%10 = load i64, i64* @errno
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @err(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %15
15: ; preds = %12, %2
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @errx(i32 %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %1)
br label %22
22: ; preds = %19, %15
ret i64 %9
}