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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ free(char *);
char *strchr(char *, char);
char *strdup(char *);
int strlen(char *);
int getrange_min_max(char *buf, u_int32_t *range_min, u_int32_t *range_max) {
  int i;
  char *dup, *ptr;
  u_int32_t min, max;
  if (!buf || strlen(buf) < 3)
    return -1;
  dup = strdup(buf);
  if (!dup)
    return -1;
  ptr = strchr(dup, ':');
  if (!ptr)
    goto error;
  *ptr++ = 0;
  i = atoi(dup);
  if (i < 1)
    goto error;
  min = i;
  i = atoi(ptr);
  if (i < 1)
    goto error;
  max = i;
  if (min >= max)
    goto error;
  *range_min = min;
  *range_max = max;
  free(dup);
  return 0;
error:
  free(dup);
  return -1;
}


x86 assembly (clang, -O0):
<getrange_min_max>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1181 <getrange_min_max+0x31>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x3,%eax
jge    118d <getrange_min_max+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    126f <getrange_min_max+0x11f>
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11b1 <getrange_min_max+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    126f <getrange_min_max+0x11f>
mov    -0x30(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11d3 <getrange_min_max+0x83>
jmp    125f <getrange_min_max+0x10f>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jge    1200 <getrange_min_max+0xb0>
jmp    125f <getrange_min_max+0x10f>
mov    -0x24(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jge    1221 <getrange_min_max+0xd1>
jmp    125f <getrange_min_max+0x10f>
mov    -0x24(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jl     1238 <getrange_min_max+0xe8>
jmp    125f <getrange_min_max+0x10f>
mov    -0x3c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    126f <getrange_min_max+0x11f>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getrange_min_max>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%ebx
test   %rdi,%rdi
je     11d9 <getrange_min_max+0x89>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbp
call   1040 <strlen@plt>
cmp    $0x3,%eax
jl     11d9 <getrange_min_max+0x89>
mov    %rbp,%rdi
call   1070 <strdup@plt>
test   %rax,%rax
je     11d9 <getrange_min_max+0x89>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     11d1 <getrange_min_max+0x81>
mov    %rax,%rbp
movb   $0x0,(%rax)
mov    %r12,%rdi
call   1060 <atoi@plt>
test   %eax,%eax
jle    11d1 <getrange_min_max+0x81>
mov    %eax,%r13d
add    $0x1,%rbp
mov    %rbp,%rdi
call   1060 <atoi@plt>
test   %eax,%eax
jle    11d1 <getrange_min_max+0x81>
cmp    %eax,%r13d
jge    11d1 <getrange_min_max+0x81>
mov    %r13d,(%r15)
mov    %eax,(%r14)
xor    %ebx,%ebx
mov    %r12,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getrange_min_max(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
%18 = icmp slt i32 %17, 3
br i1 %18, label %19, label %20
19: ; preds = %15, %3
store i32 -1, i32* %4
br label %63
20: ; preds = %15
%21 = load i8*, i8** %5
%22 = call i8* @strdup(i8* %21)
store i8* %22, i8** %9
%23 = load i8*, i8** %9
%24 = icmp ne i8* %23, null
br i1 %24, label %26, label %25
25: ; preds = %20
store i32 -1, i32* %4
br label %63
26: ; preds = %20
%27 = load i8*, i8** %9
%28 = call i8* @strchr(i8* %27, i8 signext 58)
store i8* %28, i8** %10
%29 = load i8*, i8** %10
%30 = icmp ne i8* %29, null
br i1 %30, label %32, label %31
31: ; preds = %26
br label %60
32: ; preds = %26
%33 = load i8*, i8** %10
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %10
store i8 0, i8* %33
%35 = load i8*, i8** %9
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = icmp slt i32 %37, 1
br i1 %38, label %39, label %40
39: ; preds = %32
br label %60
40: ; preds = %32
%41 = load i32, i32* %8
store i32 %41, i32* %11
%42 = load i8*, i8** %10
%43 = call i32 @atoi(i8* %42)
store i32 %43, i32* %8
%44 = load i32, i32* %8
%45 = icmp slt i32 %44, 1
br i1 %45, label %46, label %47
46: ; preds = %40
br label %60
47: ; preds = %40
%48 = load i32, i32* %8
store i32 %48, i32* %12
%49 = load i32, i32* %11
%50 = load i32, i32* %12
%51 = icmp sge i32 %49, %50
br i1 %51, label %52, label %53
52: ; preds = %47
br label %60
53: ; preds = %47
%54 = load i32, i32* %11
%55 = load i32*, i32** %6
store i32 %54, i32* %55
%56 = load i32, i32* %12
%57 = load i32*, i32** %7
store i32 %56, i32* %57
%58 = load i8*, i8** %9
%59 = call i32 @free(i8* %58)
store i32 0, i32* %4
br label %63
60: ; preds = %52, %46, %39, %31
%61 = load i8*, i8** %9
%62 = call i32 @free(i8* %61)
store i32 -1, i32* %4
br label %63
63: ; preds = %60, %53, %25, %19
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
define i32 @getrange_min_max(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %27, label %5
5: ; preds = %3
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp slt i32 %6, 3
br i1 %7, label %27, label %8
8: ; preds = %5
%9 = tail call i8* @strdup(i8* %0)
%10 = icmp eq i8* %9, null
br i1 %10, label %27, label %11
11: ; preds = %8
%12 = tail call i8* @strchr(i8* %9, i8 signext 58)
%13 = icmp eq i8* %12, null
br i1 %13, label %24, label %14
14: ; preds = %11
store i8 0, i8* %12
%15 = tail call i32 @atoi(i8* %9)
%16 = icmp slt i32 %15, 1
br i1 %16, label %24, label %17
17: ; preds = %14
%18 = getelementptr inbounds i8, i8* %12, i64 1
%19 = tail call i32 @atoi(i8* %18)
%20 = icmp sgt i32 %19, 0
%21 = icmp slt i32 %15, %19
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 %15, i32* %1
store i32 %19, i32* %2
br label %24
24: ; preds = %11, %14, %17, %23
%25 = phi i32 [ 0, %23 ], [ -1, %17 ], [ -1, %14 ], [ -1, %11 ]
%26 = tail call i32 @free(i8* %9)
br label %27
27: ; preds = %24, %8, %3, %5
%28 = phi i32 [ -1, %5 ], [ -1, %3 ], [ -1, %8 ], [ %25, %24 ]
ret i32 %28
}