#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 /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int ArgPos(char *str, int argc, char **argv) {
  int a;
  for (a = 1; a < argc; a++)
    if (!strcmp(str, argv[a])) {
      if (a == argc - 1) {
        fprintf(stderr, "Argument missing for %s\n", str);
        exit(1);
      }
      return a;
    }
  return -1;
}


x86 assembly (clang, -O0):
<ArgPos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c6 <ArgPos+0x96>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11b3 <ArgPos+0x83>
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11a8 <ArgPos+0x78>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe67(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11cd <ArgPos+0x9d>
jmp    11b8 <ArgPos+0x88>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114a <ArgPos+0x1a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ArgPos>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%r14d
cmp    $0x2,%esi
jl     1178 <ArgPos+0x48>
mov    %rdx,%r12
mov    %rdi,%r15
mov    %esi,%ebp
mov    $0x1,%ebx
mov    (%r12,%rbx,8),%rsi
mov    %r15,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1170 <ArgPos+0x40>
add    $0x1,%rbx
add    $0xffffffffffffffff,%rbp
cmp    $0x1,%rbp
jne    1150 <ArgPos+0x20>
jmp    1178 <ArgPos+0x48>
cmp    $0x2,%ebp
je     1184 <ArgPos+0x54>
mov    %ebx,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
mov    %r15,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Argument missing for %s\0A\00"
define i32 @ArgPos(i8* %0, i32 %1, i8** nocapture %2) {
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %24
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %21
%8 = phi i64 [ 1, %5 ], [ %22, %21 ]
%9 = getelementptr inbounds i8*, i8** %2, i64 %8
%10 = load i8*, i8** %9
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(1) %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %7
%14 = trunc i64 %8 to i32
%15 = add nsw i32 %1, -1
%16 = icmp eq i32 %15, %14
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %7
%22 = add nuw nsw i64 %8, 1
%23 = icmp eq i64 %22, %6
br i1 %23, label %24, label %7
24: ; preds = %21, %3, %13
%25 = phi i32 [ %14, %13 ], [ -1, %3 ], [ -1, %21 ]
ret i32 %25
}