#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*/ EXIT_FAILURE;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
unsigned long strtoul(char const *, char **, int);
unsigned int parse_cid(const char *str) {
  char *endptr = NULL;
  unsigned long n;
  errno = 0;
  n = strtoul(str, &endptr, 10);
  if (errno || *endptr != '\0') {
    fprintf(stderr, "malformed CID \"%s\"\n", str);
    exit(EXIT_FAILURE);
  }
  return n;
}


x86 assembly (clang, -O0):
<parse_cid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0x2e8d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e69(%rip),%rax
cmpq   $0x0,(%rax)
jne    1189 <parse_cid+0x59>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b0 <parse_cid+0x80>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe63(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_cid>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movq   $0x0,(%rsp)
mov    0x2e92(%rip),%rbx
movq   $0x0,(%rbx)
mov    %rsp,%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
cmpq   $0x0,(%rbx)
jne    1171 <parse_cid+0x41>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    1171 <parse_cid+0x41>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
mov    %r14,%rdx
call   1030 <fprintf@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [20 x i8] c"malformed CID \22%s\22\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @parse_cid(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
store i8* null, i8** %3
store i64 0, i64* @errno
%5 = load i8*, i8** %2
%6 = call i64 @strtoul(i8* %5, i8** %3, i32 10)
store i64 %6, i64* %4
%7 = load i64, i64* @errno
%8 = icmp ne i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %9, %1
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %2
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %9
%21 = load i64, i64* %4
%22 = trunc i64 %21 to i32
ret i32 %22
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [20 x i8] c"malformed CID \22%s\22\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @parse_cid(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
store i64 0, i64* @errno
%4 = call i64 @strtoul(i8* %0, i8** %2, i32 10)
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %7, %1
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %7
%17 = trunc i64 %4 to i32
ret i32 %17
}