#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 INT_MAX;
int /*<<< orphan*/ fatal_error(char *, char const *);
int sscanf(char const *, char *, int *, int *, ...);
int parse_loop(const char *string, int *start, int *end, int *step) {
  int i;
  i = sscanf(string, "%d:%d:%d", start, end, step);
  if (i == 2) {
    *step = 1;
  } else if (i == 1) {
    i = sscanf(string, "%d::%d", start, step);
    if (i == 2) {
      *end = INT_MAX;
    } else {
      *step = 1;
      *end = INT_MAX;
    }
  } else if (i != 3)
    fatal_error("parse_loop: expected start:end:step found %s", string);
  if (*start <= 0)
    fatal_error("parse_loop: start <= 0 %s", string);
  if (*end < *start)
    fatal_error("parse_loop: end < start %s", string);
  if (*step <= 0)
    fatal_error("parse_loop: step <= 0 %s", string);
  return 0;
}


x86 assembly (clang, -O0):
<parse_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xeb1(%rip),%rsi
mov    $0x0,%al
call   1040 <sscanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x2,-0x24(%rbp)
jne    1172 <parse_loop+0x52>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
jmp    11f9 <parse_loop+0xd9>
cmpl   $0x1,-0x24(%rbp)
jne    11d5 <parse_loop+0xb5>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1040 <sscanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x2,-0x24(%rbp)
jne    11b7 <parse_loop+0x97>
mov    0x2e3e(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11d0 <parse_loop+0xb0>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
mov    0x2e20(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11f4 <parse_loop+0xd4>
cmpl   $0x3,-0x24(%rbp)
je     11ef <parse_loop+0xcf>
mov    -0x8(%rbp),%rsi
lea    0xe26(%rip),%rdi
call   1030 <fatal_error@plt>
jmp    11f4 <parse_loop+0xd4>
jmp    11f9 <parse_loop+0xd9>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jg     1216 <parse_loop+0xf6>
mov    -0x8(%rbp),%rsi
lea    0xe2c(%rip),%rdi
call   1030 <fatal_error@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    1238 <parse_loop+0x118>
mov    -0x8(%rbp),%rsi
lea    0xe24(%rip),%rdi
call   1030 <fatal_error@plt>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jg     1255 <parse_loop+0x135>
mov    -0x8(%rbp),%rsi
lea    0xe22(%rip),%rdi
call   1030 <fatal_error@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_loop>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xec5(%rip),%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     1163 <parse_loop+0x43>
cmp    $0x3,%eax
je     11a4 <parse_loop+0x84>
cmp    $0x2,%eax
jne    1195 <parse_loop+0x75>
movl   $0x1,(%r15)
jmp    11a4 <parse_loop+0x84>
lea    0xe9f(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1040 <sscanf@plt>
cmp    $0x2,%eax
je     1186 <parse_loop+0x66>
movl   $0x1,(%r15)
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r12)
jmp    11a4 <parse_loop+0x84>
lea    0xe74(%rip),%rdi
mov    %r14,%rsi
call   1030 <fatal_error@plt>
mov    (%rbx),%eax
test   %eax,%eax
jle    11c4 <parse_loop+0xa4>
cmp    %eax,(%r12)
jl     11db <parse_loop+0xbb>
cmpl   $0x0,(%r15)
jle    11f0 <parse_loop+0xd0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe72(%rip),%rdi
mov    %r14,%rsi
call   1030 <fatal_error@plt>
mov    (%rbx),%eax
cmp    %eax,(%r12)
jge    11b0 <parse_loop+0x90>
lea    0xe75(%rip),%rdi
mov    %r14,%rsi
call   1030 <fatal_error@plt>
cmpl   $0x0,(%r15)
jg     11b6 <parse_loop+0x96>
lea    0xe7b(%rip),%rdi
mov    %r14,%rsi
call   1030 <fatal_error@plt>
jmp    11b6 <parse_loop+0x96>

LLVM IR (-O0):
@.str = [9 x i8] c"%d:%d:%d\00"
@.str.1 = [7 x i8] c"%d::%d\00"
@INT_MAX = global i32 0
@.str.2 = [45 x i8] c"parse_loop: expected start:end:step found %s\00"
@.str.3 = [26 x i8] c"parse_loop: start <= 0 %s\00"
@.str.4 = [27 x i8] c"parse_loop: end < start %s\00"
@.str.5 = [25 x i8] c"parse_loop: step <= 0 %s\00"
define i32 @parse_loop(i8* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%10 = load i8*, i8** %5
%11 = load i32*, i32** %6
%12 = load i32*, i32** %7
%13 = load i32*, i32** %8
%14 = call i32 (i8*, i8*, i32*, i32*, ...) @sscanf(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %11, i32* %12, i32* %13)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = load i32*, i32** %8
store i32 1, i32* %18
br label %45
19: ; preds = %4
%20 = load i32, i32* %9
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %37
22: ; preds = %19
%23 = load i8*, i8** %5
%24 = load i32*, i32** %6
%25 = load i32*, i32** %8
%26 = call i32 (i8*, i8*, i32*, i32*, ...) @sscanf(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %24, i32* %25)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp eq i32 %27, 2
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i32, i32* @INT_MAX
%31 = load i32*, i32** %7
store i32 %30, i32* %31
br label %36
32: ; preds = %22
%33 = load i32*, i32** %8
store i32 1, i32* %33
%34 = load i32, i32* @INT_MAX
%35 = load i32*, i32** %7
store i32 %34, i32* %35
br label %36
36: ; preds = %32, %29
br label %44
37: ; preds = %19
%38 = load i32, i32* %9
%39 = icmp ne i32 %38, 3
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i8*, i8** %5
%42 = call i32 @fatal_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %40, %37
br label %44
44: ; preds = %43, %36
br label %45
45: ; preds = %44, %17
%46 = load i32*, i32** %6
%47 = load i32, i32* %46
%48 = icmp sle i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %45
%50 = load i8*, i8** %5
%51 = call i32 @fatal_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %49, %45
%53 = load i32*, i32** %7
%54 = load i32, i32* %53
%55 = load i32*, i32** %6
%56 = load i32, i32* %55
%57 = icmp slt i32 %54, %56
br i1 %57, label %58, label %61
58: ; preds = %52
%59 = load i8*, i8** %5
%60 = call i32 @fatal_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %59)
br label %61
61: ; preds = %58, %52
%62 = load i32*, i32** %8
%63 = load i32, i32* %62
%64 = icmp sle i32 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %61
%66 = load i8*, i8** %5
%67 = call i32 @fatal_error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %66)
br label %68
68: ; preds = %65, %61
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"%d:%d:%d\00"
@.str.1 = [7 x i8] c"%d::%d\00"
@INT_MAX = global i32 0
@.str.2 = [45 x i8] c"parse_loop: expected start:end:step found %s\00"
@.str.3 = [26 x i8] c"parse_loop: start <= 0 %s\00"
@.str.4 = [27 x i8] c"parse_loop: end < start %s\00"
@.str.5 = [25 x i8] c"parse_loop: step <= 0 %s\00"
define i32 @parse_loop(i8* %0, i32* %1, i32* %2, i32* %3) {
%5 = tail call i32 (i8*, i8*, i32*, i32*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
switch i32 %5, label %14 [
i32 2, label %6
i32 1, label %7
i32 3, label %16
]
6: ; preds = %4
store i32 1, i32* %3
br label %16
7: ; preds = %4
%8 = tail call i32 (i8*, i8*, i32*, i32*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %3)
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = load i32, i32* @INT_MAX
store i32 %11, i32* %2
br label %16
12: ; preds = %7
store i32 1, i32* %3
%13 = load i32, i32* @INT_MAX
store i32 %13, i32* %2
br label %16
14: ; preds = %4
%15 = tail call i32 @fatal_error(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %16
16: ; preds = %4, %12, %10, %14, %6
%17 = load i32, i32* %1
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i32 @fatal_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%21 = load i32, i32* %1
br label %22
22: ; preds = %19, %16
%23 = phi i32 [ %21, %19 ], [ %17, %16 ]
%24 = load i32, i32* %2
%25 = icmp slt i32 %24, %23
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = tail call i32 @fatal_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %28
28: ; preds = %26, %22
%29 = load i32, i32* %3
%30 = icmp slt i32 %29, 1
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = tail call i32 @fatal_error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %0)
br label %33
33: ; preds = %31, %28
ret i32 0
}