#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
void scanone(int argc, char *argv[], int i, int *varptr) {
  if (i >= argc || sscanf(argv[i], "%i", varptr) != 1) {
    fprintf(stderr, "Bad argument %s\n", i < argc ? argv[i] : argv[argc - 1]);
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<scanone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1177 <scanone+0x47>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe97(%rip),%rsi
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     11d6 <scanone+0xa6>
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a4 <scanone+0x74>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
jmp    11b9 <scanone+0x89>
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rdx
lea    0xe3c(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scanone>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%ebx
cmp    %edi,%edx
jge    115f <scanone+0x2f>
movslq %ebp,%rax
mov    (%r14,%rax,8),%rdi
lea    0xeb3(%rip),%rsi
mov    %rcx,%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    115f <scanone+0x2f>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    -0x1(%rbx),%eax
cmp    %ebx,%ebp
mov    0x2e75(%rip),%rcx
mov    (%rcx),%edi
cmovl  %ebp,%eax
cltq
mov    (%r14,%rax,8),%rdx
lea    0xe86(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"Bad argument %s\0A\00"
define void @scanone(i32 %0, i8** %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32*
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%9 = load i32, i32* %7
%10 = load i32, i32* %5
%11 = icmp sge i32 %9, %10
br i1 %11, label %21, label %12
12: ; preds = %4
%13 = load i8**, i8*** %6
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = load i32*, i32** %8
%19 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %18)
%20 = icmp ne i32 %19, 1
br i1 %20, label %21, label %43
21: ; preds = %12, %4
%22 = load i32, i32* @stderr
%23 = load i32, i32* %7
%24 = load i32, i32* %5
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i8**, i8*** %6
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
br label %39
32: ; preds = %21
%33 = load i8**, i8*** %6
%34 = load i32, i32* %5
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %33, i64 %36
%38 = load i8*, i8** %37
br label %39
39: ; preds = %32, %26
%40 = phi i8* [ %31, %26 ], [ %38, %32 ]
%41 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %40)
%42 = call i32 @exit(i32 -1)
unreachable
43: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"Bad argument %s\0A\00"
define void @scanone(i32 %0, i8** nocapture %1, i32 %2, i32* %3) {
%5 = icmp slt i32 %2, %0
br i1 %5, label %6, label %12
6: ; preds = %4
%7 = sext i32 %2 to i64
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = tail call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%11 = icmp eq i32 %10, 1
br i1 %11, label %21, label %12
12: ; preds = %6, %4
%13 = load i32, i32* @stderr
%14 = add nsw i32 %0, -1
%15 = select i1 %5, i32 %2, i32 %14
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 -1)
unreachable
21: ; preds = %6
ret void
}