#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*/ printf(char *, char *);
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) {
        printf("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    11bd <ArgPos+0x8d>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11aa <ArgPos+0x7a>
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    119f <ArgPos+0x6f>
mov    -0x10(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c4 <ArgPos+0x94>
jmp    11af <ArgPos+0x7f>
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   1040 <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
lea    0xe75(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.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 = %34, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %37
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 %33, 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 %31
27: ; preds = %22
%28 = load i8*, i8** %5
%29 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %22
%32 = load i32, i32* %8
store i32 %32, i32* %4
br label %38
33: ; preds = %13
br label %34
34: ; preds = %33
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
br label %9
37: ; preds = %9
store i32 -1, i32* %4
br label %38
38: ; preds = %37, %31
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@.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 %23
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %20
%8 = phi i64 [ 1, %5 ], [ %21, %20 ]
%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 %20
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 %23
17: ; preds = %13
%18 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %7
%21 = add nuw nsw i64 %8, 1
%22 = icmp eq i64 %21, %6
br i1 %22, label %23, label %7
23: ; preds = %20, %3, %13
%24 = phi i32 [ %14, %13 ], [ -1, %3 ], [ -1, %20 ]
ret i32 %24
}