#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 int /*<<< orphan*/ u_long;

/* Variables and functions */
int /*<<< orphan*/ err(int, char *, char const *);
scalar_t__ errno;
int /*<<< orphan*/ errx(int, char *, char const *, char const *);
int /*<<< orphan*/ strtoul(char const *, char **, int);
u_long id(const char *name, const char *type) {
  u_long val;
  char *ep;
  errno = 0;
  val = strtoul(name, &ep, 10);
  if (errno)
    err(1, "%s", name);
  if (*ep != '\0')
    errx(1, "%s: illegal %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),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e76(%rip),%rax
cmpq   $0x0,(%rax)
je     1189 <id+0x59>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xe7c(%rip),%rsi
call   1040 <err@plt>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b2 <id+0x82>
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%edi
lea    0xe56(%rip),%rsi
call   1030 <errx@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<id>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e9c(%rip),%rbp
movq   $0x0,0x0(%rbp)
mov    %rsp,%rsi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %eax,%r15d
cmpq   $0x0,0x0(%rbp)
je     1177 <id+0x47>
lea    0xe96(%rip),%rsi
mov    $0x1,%edi
mov    %rbx,%rdx
call   1040 <err@plt>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     1197 <id+0x67>
lea    0xe7c(%rip),%rsi
mov    $0x1,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <errx@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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