#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*/ errno;
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int optind;
long strtol(int /*<<< orphan*/, char **, int);
int /*<<< orphan*/ warnx(char *, ...);
long shared_parse_size(int argc, char *argv[]) {
  int opt;
  long shm_size = -1;
  char *notconv = "";
  if (argc < 2) {
    warnx("Arguments missing");
    return -1;
  }
  while ((opt = getopt(argc, argv, "m:")) != -1) {
    switch (opt) {
    case 'm':
      errno = 0;
      shm_size = strtol(optarg, &notconv, 10);
      if (errno != 0 || *notconv != '\0' || shm_size < 1) {
        warnx("Invalid argument to: %c", opt);
        return -1;
      }
      break;
    default:
      return -1;
    }
  }
  if (optind < argc) {
    warnx("Non-option arguments present");
    return -1;
  }
  return shm_size;
}


x86 assembly (clang, -O0):
<shared_parse_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0xffffffffffffffff,-0x28(%rbp)
ff
lea    0xec6(%rip),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    1177 <shared_parse_size+0x47>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <warnx@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1269 <shared_parse_size+0x139>
jmp    117c <shared_parse_size+0x4c>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
lea    0xe88(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     1234 <shared_parse_size+0x104>
mov    -0x1c(%rbp),%eax
sub    $0x6d,%eax
jne    1222 <shared_parse_size+0xf2>
jmp    11ac <shared_parse_size+0x7c>
mov    0x2e1d(%rip),%rax
movl   $0x0,(%rax)
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    0x2df5(%rip),%rax
cmpl   $0x0,(%rax)
jne    11ff <shared_parse_size+0xcf>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11ff <shared_parse_size+0xcf>
cmpq   $0x1,-0x28(%rbp)
jge    121d <shared_parse_size+0xed>
mov    -0x1c(%rbp),%esi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1030 <warnx@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1269 <shared_parse_size+0x139>
jmp    122f <shared_parse_size+0xff>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1269 <shared_parse_size+0x139>
jmp    117c <shared_parse_size+0x4c>
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
cmp    -0xc(%rbp),%eax
jge    1261 <shared_parse_size+0x131>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1030 <warnx@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1269 <shared_parse_size+0x139>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shared_parse_size>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xed2(%rip),%rax
mov    %rax,(%rsp)
cmp    $0x2,%edi
jge    115e <shared_parse_size+0x2e>
lea    0xeae(%rip),%rdi
xor    %eax,%eax
call   1030 <warnx@plt>
jmp    11f9 <shared_parse_size+0xc9>
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0xffffffffffffffff,%rbx
lea    0xea1(%rip),%r15
mov    0x2e58(%rip),%r13
mov    %rsp,%r12
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <getopt@plt>
cmp    $0x6d,%eax
jne    11dd <shared_parse_size+0xad>
movl   $0x0,0x0(%r13)
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
cmpl   $0x0,0x0(%r13)
jne    11c8 <shared_parse_size+0x98>
mov    %rax,%rbx
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
jne    11c8 <shared_parse_size+0x98>
test   %rbx,%rbx
jg     1180 <shared_parse_size+0x50>
lea    0xe46(%rip),%rdi
mov    $0x6d,%esi
xor    %eax,%eax
call   1030 <warnx@plt>
jmp    11f9 <shared_parse_size+0xc9>
cmp    $0xffffffff,%eax
jne    11f9 <shared_parse_size+0xc9>
mov    0x2df7(%rip),%rax
cmp    %ebp,(%rax)
jge    1200 <shared_parse_size+0xd0>
lea    0xe39(%rip),%rdi
jmp    1152 <shared_parse_size+0x22>
mov    $0xffffffffffffffff,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [18 x i8] c"Arguments missing\00"
@.str.2 = [3 x i8] c"m:\00"
@errno = global i32 0
@optarg = global i32 0
@.str.3 = [24 x i8] c"Invalid argument to: %c\00"
@optind = global i32 0
@.str.4 = [29 x i8] c"Non-option arguments present\00"
define i64 @shared_parse_size(i32 %0, i8** %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 -1, i64* %7
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %8
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i64 -1, i64* %3
br label %48
13: ; preds = %2
br label %14
14: ; preds = %39, %13
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 %17, i32* %6
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %40
19: ; preds = %14
%20 = load i32, i32* %6
switch i32 %20, label %38 [
i32 109, label %21
]
21: ; preds = %19
store i32 0, i32* @errno
%22 = load i32, i32* @optarg
%23 = call i64 @strtol(i32 %22, i8** %8, i32 10)
store i64 %23, i64* %7
%24 = load i32, i32* @errno
%25 = icmp ne i32 %24, 0
br i1 %25, label %34, label %26
26: ; preds = %21
%27 = load i8*, i8** %8
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = load i64, i64* %7
%33 = icmp slt i64 %32, 1
br i1 %33, label %34, label %37
34: ; preds = %31, %26, %21
%35 = load i32, i32* %6
%36 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %35)
store i64 -1, i64* %3
br label %48
37: ; preds = %31
br label %39
38: ; preds = %19
store i64 -1, i64* %3
br label %48
39: ; preds = %37
br label %14
40: ; preds = %14
%41 = load i32, i32* @optind
%42 = load i32, i32* %4
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
store i64 -1, i64* %3
br label %48
46: ; preds = %40
%47 = load i64, i64* %7
store i64 %47, i64* %3
br label %48
48: ; preds = %46, %44, %38, %34, %11
%49 = load i64, i64* %3
ret i64 %49
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [18 x i8] c"Arguments missing\00"
@.str.2 = [3 x i8] c"m:\00"
@errno = global i32 0
@optarg = global i32 0
@.str.3 = [24 x i8] c"Invalid argument to: %c\00"
@optind = global i32 0
@.str.4 = [29 x i8] c"Non-option arguments present\00"
define i64 @shared_parse_size(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %29
8: ; preds = %2, %16
%9 = phi i64 [ %13, %16 ], [ -1, %2 ]
%10 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
switch i32 %10, label %29 [
i32 -1, label %24
i32 109, label %11
]
11: ; preds = %8
store i32 0, i32* @errno
%12 = load i32, i32* @optarg
%13 = call i64 @strtol(i32 %12, i8** %3, i32 10)
%14 = load i32, i32* @errno
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
%20 = icmp slt i64 %13, 1
%21 = select i1 %19, i1 true, i1 %20
br i1 %21, label %22, label %8
22: ; preds = %16, %11
%23 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 109)
br label %29
24: ; preds = %8
%25 = load i32, i32* @optind
%26 = icmp slt i32 %25, %0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %8, %24, %27, %22, %6
%30 = phi i64 [ -1, %6 ], [ -1, %22 ], [ -1, %27 ], [ %9, %24 ], [ -1, %8 ]
ret i64 %30
}