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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ printf(char *);
char *strdup(char *);
char *strsep(char **, char *);
int parse_range(uid_t *min, int *offset, char *buf) {
  char *value, *tmp_ptr = strdup(buf);
  int range = 0;
  ;
  value = strsep(&tmp_ptr, "-");
  *min = atoi(value);
  ;
  if (tmp_ptr) {
    value = strsep(&tmp_ptr, "-");
    range = atoi(value);
    if (range < *min) {
      printf("max id should be larger than min id\n");
      return -1;
    }
    *offset = range - *min + 1;
    ;
  } else {
    printf("argument should be in the form of min-max\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1040 <strsep@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x30(%rbp)
je     11f6 <parse_range+0xb6>
lea    -0x30(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1040 <strsep@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    11df <parse_range+0x9f>
lea    0xe34(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1215 <parse_range+0xd5>
mov    -0x34(%rbp),%ecx
mov    -0x10(%rbp),%rax
sub    (%rax),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    120e <parse_range+0xce>
lea    0xe2a(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1215 <parse_range+0xd5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_range>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdx,%rdi
call   1060 <strdup@plt>
mov    %rax,(%rsp)
lea    0xea3(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strsep@plt>
mov    %rax,%rdi
call   1050 <atoi@plt>
mov    %eax,(%rbx)
cmpq   $0x0,(%rsp)
je     119a <parse_range+0x5a>
lea    0xe83(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strsep@plt>
mov    %rax,%rdi
call   1050 <atoi@plt>
sub    (%rbx),%eax
jge    11ad <parse_range+0x6d>
lea    0xe94(%rip),%rdi
jmp    11a1 <parse_range+0x61>
lea    0xe61(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    11b5 <parse_range+0x75>
add    $0x1,%eax
mov    %eax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@.str.1 = [37 x i8] c"max id should be larger than min id\0A\00"
@.str.2 = [43 x i8] c"argument should be in the form of min-max\0A\00"
define i32 @parse_range(i32* %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %7
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %9
store i32 0, i32* %10
%13 = call i8* @strsep(i8** %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = call i32 @atoi(i8* %14)
%16 = load i32*, i32** %5
store i32 %15, i32* %16
%17 = load i8*, i8** %9
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %36
19: ; preds = %3
%20 = call i8* @strsep(i8** %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %20, i8** %8
%21 = load i8*, i8** %8
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %10
%23 = load i32, i32* %10
%24 = load i32*, i32** %5
%25 = load i32, i32* %24
%26 = icmp slt i32 %23, %25
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %39
29: ; preds = %19
%30 = load i32, i32* %10
%31 = load i32*, i32** %5
%32 = load i32, i32* %31
%33 = sub nsw i32 %30, %32
%34 = add nsw i32 %33, 1
%35 = load i32*, i32** %6
store i32 %34, i32* %35
br label %38
36: ; preds = %3
%37 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %39
38: ; preds = %29
store i32 0, i32* %4
br label %39
39: ; preds = %38, %36, %27
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@str = [42 x i8] c"argument should be in the form of min-max\00"
@str.3 = [36 x i8] c"max id should be larger than min id\00"
define i32 @parse_range(i32* nocapture %0, i32* nocapture writeonly %1, i8* nocapture %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i8* @strdup(i8* %2)
store i8* %6, i8** %4
%7 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @atoi(i8* %7)
store i32 %8, i32* %0
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %21, label %11
11: ; preds = %3
%12 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @atoi(i8* %12)
%14 = load i32, i32* %0
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0))
br label %23
18: ; preds = %11
%19 = add i32 %13, 1
%20 = sub i32 %19, %14
store i32 %20, i32* %1
br label %23
21: ; preds = %3
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %23
23: ; preds = %18, %21, %16
%24 = phi i32 [ -1, %16 ], [ 0, %18 ], [ -1, %21 ]
ret i32 %24
}