#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 */
scalar_t__ ERANGE;
unsigned long INT_MAX;
int /*<<< orphan*/ die_usage();
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
unsigned long strtoul(char const *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int parse_int(const char *size) {
  unsigned long s;
  errno = 0;
  s = strtoul(size, NULL, 0);
  if (errno) {
    fprintf(stderr, "Invalid sndbuf size %s (%s)\n", size, strerror(errno));
    die_usage();
  }
  if (s > INT_MAX) {
    fprintf(stderr, "Invalid sndbuf size %s (%s)\n", size, strerror(ERANGE));
    die_usage();
  }
  return (int)s;
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e75(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e54(%rip),%rax
cmpq   $0x0,(%rax)
je     11be <parse_int+0x7e>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xe4e(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x0,%al
call   1060 <die_usage@plt>
mov    -0x10(%rbp),%rax
mov    0x2e1f(%rip),%rcx
cmp    (%rcx),%rax
jbe    1212 <parse_int+0xd2>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xdfa(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x0,%al
call   1060 <die_usage@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    0x2e7a(%rip),%rbp
movq   $0x0,0x0(%rbp)
xor    %esi,%esi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,%r14
mov    0x0(%rbp),%rdi
test   %rdi,%rdi
je     1194 <parse_int+0x54>
mov    0x2e5e(%rip),%rax
mov    (%rax),%ebp
call   1050 <strerror@plt>
lea    0xe80(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
xor    %eax,%eax
call   1060 <die_usage@plt>
mov    0x2e4d(%rip),%rax
cmp    (%rax),%r14
jbe    11d3 <parse_int+0x93>
mov    0x2e29(%rip),%rax
mov    (%rax),%ebp
mov    0x2e30(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
lea    0xe41(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
xor    %eax,%eax
call   1060 <die_usage@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [29 x i8] c"Invalid sndbuf size %s (%s)\0A\00"
@INT_MAX = global i64 0
@ERANGE = global i64 0
define i32 @parse_int(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* @errno
%4 = load i8*, i8** %2
%5 = call i64 @strtoul(i8* %4, i32* null, i32 0)
store i64 %5, i64* %3
%6 = load i64, i64* @errno
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %2
%11 = load i64, i64* @errno
%12 = call i8* @strerror(i64 %11)
%13 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %12)
%14 = call i32 (...) @die_usage()
br label %15
15: ; preds = %8, %1
%16 = load i64, i64* %3
%17 = load i64, i64* @INT_MAX
%18 = icmp ugt i64 %16, %17
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %2
%22 = load i64, i64* @ERANGE
%23 = call i8* @strerror(i64 %22)
%24 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %23)
%25 = call i32 (...) @die_usage()
br label %26
26: ; preds = %19, %15
%27 = load i64, i64* %3
%28 = trunc i64 %27 to i32
ret i32 %28
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [29 x i8] c"Invalid sndbuf size %s (%s)\0A\00"
@INT_MAX = global i64 0
@ERANGE = global i64 0
define i32 @parse_int(i8* %0) {
store i64 0, i64* @errno
%2 = tail call i64 @strtoul(i8* nocapture %0, i32* null, i32 0)
%3 = load i64, i64* @errno
%4 = icmp eq i64 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i8* @strerror(i64 %3)
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %7)
%9 = tail call i32 (...) @die_usage()
br label %10
10: ; preds = %5, %1
%11 = load i64, i64* @INT_MAX
%12 = icmp ugt i64 %2, %11
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = load i64, i64* @ERANGE
%16 = tail call i8* @strerror(i64 %15)
%17 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %16)
%18 = tail call i32 (...) @die_usage()
br label %19
19: ; preds = %13, %10
%20 = trunc i64 %2 to i32
ret i32 %20
}