#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 aclamp(long);
int /*<<< orphan*/ die(char *, char const *, ...);
scalar_t__ errno;
int /*<<< orphan*/ strerror(scalar_t__);
long strtol(char const *, char **, int);
int getrot(const char *str) {
  long val;
  char *endptr;
  if (!*str)
    die("Invalid argument '%s'\n", str);
  errno = 0;
  val = strtol(str, &endptr, 10);
  if (errno)
    die("Invalid argument '%s': %s\n", str, strerror(errno));
  if (*endptr)
    die("Invalid argument '%s'\n", str);
  return aclamp(val);
}


x86 assembly (clang, -O0):
<getrot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    116b <getrot+0x2b>
mov    -0x8(%rbp),%rsi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1050 <die@plt>
mov    0x2e6e(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e4a(%rip),%rax
cmpq   $0x0,(%rax)
je     11cb <getrot+0x8b>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <die@plt>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ea <getrot+0xaa>
mov    -0x8(%rbp),%rsi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <die@plt>
mov    -0x10(%rbp),%rdi
call   1040 <aclamp@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getrot>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
jne    1162 <getrot+0x22>
lea    0xea8(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <die@plt>
mov    0x2e77(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,%r14
mov    (%r15),%rdi
test   %rdi,%rdi
je     11a5 <getrot+0x65>
call   1060 <strerror@plt>
lea    0xe7e(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <die@plt>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     11c0 <getrot+0x80>
lea    0xe4a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <die@plt>
mov    %r14,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <aclamp@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Invalid argument '%s'\0A\00"
@errno = global i64 0
@.str.1 = [27 x i8] c"Invalid argument '%s': %s\0A\00"
define i32 @getrot(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %11
11: ; preds = %8, %1
store i64 0, i64* @errno
%12 = load i8*, i8** %2
%13 = call i64 @strtol(i8* %12, i8** %4, i32 10)
store i64 %13, i64* %3
%14 = load i64, i64* @errno
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i8*, i8** %2
%18 = load i64, i64* @errno
%19 = call i32 @strerror(i64 %18)
%20 = call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %17, i32 %19)
br label %21
21: ; preds = %16, %11
%22 = load i8*, i8** %4
%23 = load i8, i8* %22
%24 = icmp ne i8 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i8*, i8** %2
%27 = call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %25, %21
%29 = load i64, i64* %3
%30 = call i32 @aclamp(i64 %29)
ret i32 %30
}

LLVM IR (-O2):
@.str = [23 x i8] c"Invalid argument '%s'\0A\00"
@errno = global i64 0
@.str.1 = [27 x i8] c"Invalid argument '%s': %s\0A\00"
define i32 @getrot(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %6, %1
store i64 0, i64* @errno
%9 = call i64 @strtol(i8* %0, i8** %2, i32 10)
%10 = load i64, i64* @errno
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = tail call i32 @strerror(i64 %10)
%14 = tail call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %13)
br label %15
15: ; preds = %12, %8
%16 = load i8*, i8** %2
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = tail call i32 (i8*, i8*, ...) @die(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %21
21: ; preds = %19, %15
%22 = tail call i32 @aclamp(i64 %9)
ret i32 %22
}