#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;
scalar_t__ errno;
int strtol(char *, char **, int);
int GetDinnerCount(int argc, char *argv[]) {
  int ret = 0;
  if (argc == 2) {
    char *rest;
    errno = 0;
    ret = strtol(argv[1], &rest, 10);
    if (*rest != '\0' || errno == ERANGE || ret <= 0)
      return -1;
  } else
    return -1;
  return ret;
}


x86 assembly (clang, -O0):
<GetDinnerCount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    119c <GetDinnerCount+0x8c>
mov    0x2ea1(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    118b <GetDinnerCount+0x7b>
mov    0x2e6a(%rip),%rax
mov    (%rax),%rax
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%rax
je     118b <GetDinnerCount+0x7b>
cmpl   $0x0,-0x14(%rbp)
jg     1197 <GetDinnerCount+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <GetDinnerCount+0x9e>
jmp    11a8 <GetDinnerCount+0x98>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <GetDinnerCount+0x9e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetDinnerCount>:
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%ebx
cmp    $0x2,%edi
jne    1162 <GetDinnerCount+0x52>
mov    0x2eb3(%rip),%r14
movq   $0x0,(%r14)
mov    0x8(%rsi),%rdi
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    1162 <GetDinnerCount+0x52>
mov    (%r14),%rcx
mov    0x2e98(%rip),%rdx
test   %eax,%eax
mov    $0xffffffff,%esi
cmovle %esi,%eax
cmp    (%rdx),%rcx
cmove  %esi,%eax
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
define i32 @GetDinnerCount(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %28
10: ; preds = %2
store i64 0, i64* @errno
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @strtol(i8* %13, i8** %7, i32 10)
store i32 %14, i32* %6
%15 = load i8*, i8** %7
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %10
%20 = load i64, i64* @errno
%21 = load i64, i64* @ERANGE
%22 = icmp eq i64 %20, %21
br i1 %22, label %26, label %23
23: ; preds = %19
%24 = load i32, i32* %6
%25 = icmp sle i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23, %19, %10
store i32 -1, i32* %3
br label %31
27: ; preds = %23
br label %29
28: ; preds = %2
store i32 -1, i32* %3
br label %31
29: ; preds = %27
%30 = load i32, i32* %6
store i32 %30, i32* %3
br label %31
31: ; preds = %29, %28, %26
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
define i32 @GetDinnerCount(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = icmp eq i32 %0, 2
br i1 %4, label %5, label %21
5: ; preds = %2
%6 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i32 @strtol(i8* %8, i8** %3, i32 10)
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %5
br label %21
14: ; preds = %5
%15 = load i64, i64* @errno
%16 = load i64, i64* @ERANGE
%17 = icmp ne i64 %15, %16
%18 = icmp sgt i32 %9, 0
%19 = select i1 %17, i1 %18, i1 false
%20 = select i1 %19, i32 %9, i32 -1
br label %21
21: ; preds = %14, %13, %2
%22 = phi i32 [ -1, %2 ], [ -1, %13 ], [ %20, %14 ]
ret i32 %22
}