#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*/ printf(char *, ...);
scalar_t__ strcmp(char const *, char *);
long strtol(char const *, char **, int);
int get_pin_nr(int argc, const char *argv[]) {
  if (argc == 2) {
    char *eptr;
    long result;
    char zero[] = "0";
    result = strtol(argv[1], &eptr, 10);
    if (result == 0 && strcmp(argv[1], zero) != 0) {
      printf("Invalid argument: %s\n", argv[1]);
      return 1;
    }
    return (int)result;
  } else {
    printf("Missing argument.\n");
    return -1;
  }
}


x86 assembly (clang, -O0):
<get_pin_nr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11c2 <get_pin_nr+0x92>
mov    0xeb0(%rip),%ax
mov    %ax,-0x22(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b6 <get_pin_nr+0x86>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x22(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11b6 <get_pin_nr+0x86>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d7 <get_pin_nr+0xa7>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11d7 <get_pin_nr+0xa7>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_pin_nr>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    119d <get_pin_nr+0x5d>
mov    %rsi,%r14
movw   $0x30,0xe(%rsp)
mov    0x8(%rsi),%rdi
lea    0x10(%rsp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ae <get_pin_nr+0x6e>
mov    0x8(%r14),%rdi
lea    0xe(%rsp),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11ae <get_pin_nr+0x6e>
mov    0x8(%r14),%rsi
lea    0xe71(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebx
jmp    11ae <get_pin_nr+0x6e>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.get_pin_nr.zero = [2 x i8] c"0\00"
@.str = [22 x i8] c"Invalid argument: %s\0A\00"
@.str.1 = [19 x i8] c"Missing argument.\0A\00"
define i32 @get_pin_nr(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [2 x i8]
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %34
11: ; preds = %2
%12 = bitcast [2 x i8]* %8 to i8*
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i64 @strtol(i8* %15, i8** %6, i32 10)
store i64 %16, i64* %7
%17 = load i64, i64* %7
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %31
19: ; preds = %11
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%24 = call i64 @strcmp(i8* %22, i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %19
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %29)
store i32 1, i32* %3
br label %36
31: ; preds = %19, %11
%32 = load i64, i64* %7
%33 = trunc i64 %32 to i32
store i32 %33, i32* %3
br label %36
34: ; preds = %2
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %36
36: ; preds = %34, %31, %26
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [22 x i8] c"Invalid argument: %s\0A\00"
@str = [18 x i8] c"Missing argument.\00"
define i32 @get_pin_nr(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i16
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %24
6: ; preds = %2
%7 = bitcast i8** %3 to i8*
%8 = bitcast i16* %4 to i8*
store i16 48, i16* %4
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i64 @strtol(i8* %10, i8** %3, i32 10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %6
%14 = load i8*, i8** %9
%15 = call i64 @strcmp(i8* %14, i8* %8)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = load i8*, i8** %9
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %22
20: ; preds = %13, %6
%21 = trunc i64 %11 to i32
br label %22
22: ; preds = %20, %17
%23 = phi i32 [ 1, %17 ], [ %21, %20 ]
br label %26
24: ; preds = %2
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %26
26: ; preds = %24, %22
%27 = phi i32 [ %23, %22 ], [ -1, %24 ]
ret i32 %27
}