#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_FAILURE;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char const *, char *);
int /*<<< orphan*/ usage(char *);
int read_opt(int argc, char **argv, int id, void *data, const char *datatype) {
  if (strcmp(datatype, "int") == 0) {
    if (id + 1 >= argc) {
      fprintf(stderr, "incomplete input");
      usage(argv[0]);
      exit(EXIT_FAILURE);
    }
    *((int *)data) = atoi(argv[id + 1]);
  }
  return id + 1;
}


x86 assembly (clang, -O0):
<read_opt>:
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    %r8,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11e0 <read_opt+0x90>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cmp    -0x4(%rbp),%eax
jl     11c2 <read_opt+0x72>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <usage@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_opt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe98(%rip),%rsi
mov    %r8,%rdi
call   1030 <strcmp@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    118b <read_opt+0x3b>
cmp    %ebx,%ebp
jge    1198 <read_opt+0x48>
movslq %ebp,%rax
mov    (%r14,%rax,8),%rdi
call   1060 <atoi@plt>
mov    %eax,(%r15)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%r14),%rdi
call   1050 <usage@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"int\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"incomplete input\00"
@EXIT_FAILURE = global i32 0
define i32 @read_opt(i32 %0, i8** %1, i32 %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%11 = load i8*, i8** %10
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %38
14: ; preds = %5
%15 = load i32, i32* %8
%16 = add nsw i32 %15, 1
%17 = load i32, i32* %6
%18 = icmp sge i32 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%22 = load i8**, i8*** %7
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 @usage(i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %14
%29 = load i8**, i8*** %7
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %29, i64 %32
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
%36 = load i8*, i8** %9
%37 = bitcast i8* %36 to i32*
store i32 %35, i32* %37
br label %38
38: ; preds = %28, %5
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
ret i32 %40
}

LLVM IR (-O2):
@.str = [4 x i8] c"int\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"incomplete input\00"
@EXIT_FAILURE = global i32 0
define i32 @read_opt(i32 %0, i8** nocapture %1, i32 %2, i8* nocapture writeonly %3, i8* %4) {
%6 = tail call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
%8 = add nsw i32 %2, 1
br i1 %7, label %9, label %24
9: ; preds = %5
%10 = icmp slt i32 %8, %0
br i1 %10, label %18, label %11
11: ; preds = %9
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%14 = load i8*, i8** %1
%15 = tail call i32 @usage(i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %9
%19 = sext i32 %8 to i64
%20 = getelementptr inbounds i8*, i8** %1, i64 %19
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = bitcast i8* %3 to i32*
store i32 %22, i32* %23
br label %24
24: ; preds = %5, %18
ret i32 %8
}