#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *, char *);
int sscanf(char *, char *, unsigned int *, unsigned int *, unsigned int *,
           int *);
scalar_t__ strchr(char *, char);
char *mapitem(char *map, unsigned *first, unsigned *lower, unsigned *count) {
  ssize_t skip;
  while (map && *map && strchr(",;", *map))
    map++;
  if (map == NULL || *map == '\0')
    return NULL;
  if (sscanf(map, "%u:%u:%u%zn", first, lower, count, &skip) < 3)
    error(1, 0, "Invalid ID map '%s'", map);
  return map + skip;
}


x86 assembly (clang, -O0):
<mapitem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x2d(%rbp)
je     118a <mapitem+0x5a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x2d(%rbp)
je     118a <mapitem+0x5a>
mov    -0x10(%rbp),%rax
lea    0xe88(%rip),%rdi
movsbl (%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    119a <mapitem+0x6a>
jmp    11ab <mapitem+0x7b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1148 <mapitem+0x18>
cmpq   $0x0,-0x10(%rbp)
je     11c6 <mapitem+0x96>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d3 <mapitem+0xa3>
movq   $0x0,-0x8(%rbp)
jmp    1222 <mapitem+0xf2>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe19(%rip),%rsi
lea    -0x2c(%rbp),%r9
call   1040 <sscanf@plt>
cmp    $0x3,%eax
jge    1213 <mapitem+0xe3>
mov    -0x10(%rbp),%rcx
mov    $0x1,%edi
xor    %esi,%esi
lea    0xe01(%rip),%rdx
call   1050 <error@plt>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mapitem>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     11c5 <mapitem+0x95>
mov    %rdi,%rbx
mov    (%rdi),%al
test   %al,%al
je     11c5 <mapitem+0x95>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
lea    0xea1(%rip),%r13
nop
movsbl %al,%esi
mov    %r13,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     117e <mapitem+0x4e>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <mapitem+0x30>
jmp    11c5 <mapitem+0x95>
cmpb   $0x0,(%rbx)
je     11c5 <mapitem+0x95>
lea    0xe79(%rip),%rsi
lea    0xc(%rsp),%r9
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <sscanf@plt>
cmp    $0x2,%eax
jg     11bb <mapitem+0x8b>
lea    0xe63(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
mov    %rbx,%rcx
call   1050 <error@plt>
movslq 0xc(%rsp),%rax
add    %rax,%rbx
jmp    11c7 <mapitem+0x97>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c",;\00"
@.str.1 = [12 x i8] c"%u:%u:%u%zn\00"
@.str.2 = [20 x i8] c"Invalid ID map '%s'\00"
define i8* @mapitem(i8* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
br label %11
11: ; preds = %26, %4
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %24
14: ; preds = %11
%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 %24
19: ; preds = %14
%20 = load i8*, i8** %6
%21 = load i8, i8* %20
%22 = call i64 @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %21)
%23 = icmp ne i64 %22, 0
br label %24
24: ; preds = %19, %14, %11
%25 = phi i1 [ false, %14 ], [ false, %11 ], [ %23, %19 ]
br i1 %25, label %26, label %29
26: ; preds = %24
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %6
br label %11
29: ; preds = %24
%30 = load i8*, i8** %6
%31 = icmp eq i8* %30, null
br i1 %31, label %37, label %32
32: ; preds = %29
%33 = load i8*, i8** %6
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32, %29
store i8* null, i8** %5
br label %53
38: ; preds = %32
%39 = load i8*, i8** %6
%40 = load i32*, i32** %7
%41 = load i32*, i32** %8
%42 = load i32*, i32** %9
%43 = call i32 @sscanf(i8* %39, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32* %40, i32* %41, i32* %42, i32* %10)
%44 = icmp slt i32 %43, 3
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = load i8*, i8** %6
%47 = call i32 @error(i32 1, i32 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %45, %38
%49 = load i8*, i8** %6
%50 = load i32, i32* %10
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8* %52, i8** %5
br label %53
53: ; preds = %48, %37
%54 = load i8*, i8** %5
ret i8* %54
}

LLVM IR (-O2):
@.str = [3 x i8] c",;\00"
@.str.1 = [12 x i8] c"%u:%u:%u%zn\00"
@.str.2 = [20 x i8] c"Invalid ID map '%s'\00"
define i8* @mapitem(i8* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = icmp eq i8* %0, null
br i1 %7, label %32, label %8
8: ; preds = %4
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 0
br i1 %10, label %32, label %11
11: ; preds = %8, %16
%12 = phi i8 [ %18, %16 ], [ %9, %8 ]
%13 = phi i8* [ %17, %16 ], [ %0, %8 ]
%14 = tail call i64 @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %12)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = getelementptr inbounds i8, i8* %13, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %32, label %11
20: ; preds = %11
%21 = load i8, i8* %13
%22 = icmp eq i8 %21, 0
br i1 %22, label %32, label %23
23: ; preds = %20
%24 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2, i32* %3, i32* %5)
%25 = icmp slt i32 %24, 3
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @error(i32 1, i32 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %28
28: ; preds = %26, %23
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %13, i64 %30
br label %32
32: ; preds = %16, %8, %4, %20, %28
%33 = phi i8* [ %31, %28 ], [ null, %20 ], [ null, %4 ], [ null, %8 ], [ null, %16 ]
ret i8* %33
}