#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
long strtol(char *, char **, int);
int parse_int(char *str, int *dest) {
  char *end;
  long val = strtol(str, &end, 10);
  if (end == str) {
    fprintf(stderr, "Got empty string\n");
    return -1;
  }
  if (*end != '\0') {
    fprintf(stderr, "Input not integer: %s\n", str);
    return -1;
  }
  if (val < 1 || val > 256) {
    fprintf(stderr, "Integer should be between 1 and 256\n");
    return -1;
  }
  *dest = val;
  return 0;
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1177 <parse_int+0x57>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fd <parse_int+0xdd>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ae <parse_int+0x8e>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fd <parse_int+0xdd>
cmpq   $0x1,-0x28(%rbp)
jl     11c7 <parse_int+0xa7>
cmpq   $0x100,-0x28(%rbp)
jle    11ea <parse_int+0xca>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fd <parse_int+0xdd>
mov    -0x28(%rbp),%rax
mov    %eax,%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):
<parse_int>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    (%rsp),%rcx
cmp    %rbx,%rcx
je     1166 <parse_int+0x46>
cmpb   $0x0,(%rcx)
je     1178 <parse_int+0x58>
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
lea    0xebd(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    11ab <parse_int+0x8b>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
jmp    1198 <parse_int+0x78>
lea    -0x101(%rax),%rcx
cmp    $0xfffffffffffffeff,%rcx
ja     11a6 <parse_int+0x86>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    11ab <parse_int+0x8b>
mov    %eax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"Got empty string\0A\00"
@.str.1 = [23 x i8] c"Input not integer: %s\0A\00"
@.str.2 = [37 x i8] c"Integer should be between 1 and 256\0A\00"
define i32 @parse_int(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = call i64 @strtol(i8* %8, i8** %6, i32 10)
store i64 %9, i64* %7
%10 = load i8*, i8** %6
%11 = load i8*, i8** %4
%12 = icmp eq i8* %10, %11
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %38
16: ; preds = %2
%17 = load i8*, i8** %6
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %4
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %23)
store i32 -1, i32* %3
br label %38
25: ; preds = %16
%26 = load i64, i64* %7
%27 = icmp slt i64 %26, 1
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = load i64, i64* %7
%30 = icmp sgt i64 %29, 256
br i1 %30, label %31, label %34
31: ; preds = %28, %25
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %38
34: ; preds = %28
%35 = load i64, i64* %7
%36 = trunc i64 %35 to i32
%37 = load i32*, i32** %5
store i32 %36, i32* %37
store i32 0, i32* %3
br label %38
38: ; preds = %34, %31, %21, %13
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"Got empty string\0A\00"
@.str.1 = [23 x i8] c"Input not integer: %s\0A\00"
@.str.2 = [37 x i8] c"Integer should be between 1 and 256\0A\00"
define i32 @parse_int(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @strtol(i8* %0, i8** %3, i32 10)
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, %0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %25
11: ; preds = %2
%12 = load i8, i8* %6
%13 = icmp eq i8 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %25
17: ; preds = %11
%18 = add i64 %5, -257
%19 = icmp ult i64 %18, -256
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %25
23: ; preds = %17
%24 = trunc i64 %5 to i32
store i32 %24, i32* %1
br label %25
25: ; preds = %23, %20, %14, %8
%26 = phi i32 [ -1, %8 ], [ -1, %14 ], [ -1, %20 ], [ 0, %23 ]
ret i32 %26
}