#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*/ print_error(char *, char const *, ...);
int set_dec(const char *s, unsigned int *result, const char *name,
            unsigned int minval, unsigned int maxval) {
  unsigned int newval = 0;
  while (*s != '\0') {
    if (*s < '0' || *s > '9') {
      print_error("%s must be an integer", name);
      return 1;
    }
    newval = 10 * newval + *s++ - '0';
    if (newval > maxval) {
      print_error("maximum %s is %u", name, maxval);
      return 1;
    }
  }
  if (newval < minval) {
    print_error("minimum %s is %u", name, minval);
    return 1;
  }
  *result = newval;
  return 0;
}


x86 assembly (clang, -O0):
<set_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d0 <set_dec+0xc0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     1162 <set_dec+0x52>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jle    1180 <set_dec+0x70>
mov    -0x20(%rbp),%rsi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <print_error@plt>
movl   $0x1,-0x4(%rbp)
jmp    120d <set_dec+0xfd>
imul   $0xa,-0x2c(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
movsbl (%rcx),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jbe    11cb <set_dec+0xbb>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%edx
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <print_error@plt>
movl   $0x1,-0x4(%rbp)
jmp    120d <set_dec+0xfd>
jmp    1132 <set_dec+0x22>
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    11fd <set_dec+0xed>
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <print_error@plt>
movl   $0x1,-0x4(%rbp)
jmp    120d <set_dec+0xfd>
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_dec>:
push   %rax
xor    %r9d,%r9d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%rdi),%r10d
test   %r10d,%r10d
je     1155 <set_dec+0x45>
lea    -0x3a(%r10),%eax
cmp    $0xf5,%al
jbe    116f <set_dec+0x5f>
lea    (%r9,%r9,4),%eax
add    $0x1,%rdi
lea    (%r10,%rax,2),%r9d
add    $0xffffffd0,%r9d
cmp    %r8d,%r9d
jbe    1120 <set_dec+0x10>
lea    0xec9(%rip),%rdi
mov    %rdx,%rsi
mov    %r8d,%edx
jmp    1166 <set_dec+0x56>
cmp    %ecx,%r9d
jae    1187 <set_dec+0x77>
lea    0xec6(%rip),%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
xor    %eax,%eax
call   1030 <print_error@plt>
jmp    1180 <set_dec+0x70>
lea    0xe8a(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1030 <print_error@plt>
mov    $0x1,%eax
pop    %rcx
ret
mov    %r9d,(%rsi)
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"%s must be an integer\00"
@.str.1 = [17 x i8] c"maximum %s is %u\00"
@.str.2 = [17 x i8] c"minimum %s is %u\00"
define i32 @set_dec(i8* %0, i32* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %7
store i32* %1, i32** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 0, i32* %12
br label %13
13: ; preds = %47, %5
%14 = load i8*, i8** %7
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %48
18: ; preds = %13
%19 = load i8*, i8** %7
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp slt i32 %21, 48
br i1 %22, label %28, label %23
23: ; preds = %18
%24 = load i8*, i8** %7
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp sgt i32 %26, 57
br i1 %27, label %28, label %31
28: ; preds = %23, %18
%29 = load i8*, i8** %9
%30 = call i32 (i8*, i8*, ...) @print_error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %29)
store i32 1, i32* %6
br label %59
31: ; preds = %23
%32 = load i32, i32* %12
%33 = mul i32 10, %32
%34 = load i8*, i8** %7
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %7
%36 = load i8, i8* %34
%37 = sext i8 %36 to i32
%38 = add i32 %33, %37
%39 = sub i32 %38, 48
store i32 %39, i32* %12
%40 = load i32, i32* %12
%41 = load i32, i32* %11
%42 = icmp ugt i32 %40, %41
br i1 %42, label %43, label %47
43: ; preds = %31
%44 = load i8*, i8** %9
%45 = load i32, i32* %11
%46 = call i32 (i8*, i8*, ...) @print_error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %44, i32 %45)
store i32 1, i32* %6
br label %59
47: ; preds = %31
br label %13
48: ; preds = %13
%49 = load i32, i32* %12
%50 = load i32, i32* %10
%51 = icmp ult i32 %49, %50
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = load i8*, i8** %9
%54 = load i32, i32* %10
%55 = call i32 (i8*, i8*, ...) @print_error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %53, i32 %54)
store i32 1, i32* %6
br label %59
56: ; preds = %48
%57 = load i32, i32* %12
%58 = load i32*, i32** %8
store i32 %57, i32* %58
store i32 0, i32* %6
br label %59
59: ; preds = %56, %52, %43, %28
%60 = load i32, i32* %6
ret i32 %60
}

LLVM IR (-O2):
@.str = [22 x i8] c"%s must be an integer\00"
@.str.1 = [17 x i8] c"maximum %s is %u\00"
@.str.2 = [17 x i8] c"minimum %s is %u\00"
define i32 @set_dec(i8* nocapture %0, i32* nocapture writeonly %1, i8* %2, i32 %3, i32 %4) {
br label %6
6: ; preds = %17, %5
%7 = phi i8* [ %0, %5 ], [ %19, %17 ]
%8 = phi i32 [ 0, %5 ], [ %21, %17 ]
%9 = load i8, i8* %7
%10 = sext i8 %9 to i32
%11 = icmp eq i8 %9, 0
br i1 %11, label %25, label %12
12: ; preds = %6
%13 = add i8 %9, -58
%14 = icmp ult i8 %13, -10
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 (i8*, i8*, ...) @print_error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %30
17: ; preds = %12
%18 = mul i32 %8, 10
%19 = getelementptr inbounds i8, i8* %7, i64 1
%20 = add i32 %18, -48
%21 = add i32 %20, %10
%22 = icmp ugt i32 %21, %4
br i1 %22, label %23, label %6
23: ; preds = %17
%24 = tail call i32 (i8*, i8*, ...) @print_error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %4)
br label %30
25: ; preds = %6
%26 = icmp ult i32 %8, %3
br i1 %26, label %27, label %29
27: ; preds = %25
%28 = tail call i32 (i8*, i8*, ...) @print_error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %2, i32 %3)
br label %30
29: ; preds = %25
store i32 %8, i32* %1
br label %30
30: ; preds = %29, %27, %23, %15
%31 = phi i32 [ 1, %15 ], [ 1, %23 ], [ 1, %27 ], [ 0, %29 ]
ret i32 %31
}