#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 */
scalar_t__ strcmp(char *, char *);
int checkparm(int narg, char **args, char parm[]) {
  int p, found;
  found = 0;
  p = 0;
  do {
    if (0 == strcmp(args[p], parm))
      found = 1;
    else
      p++;
  } while ((p < narg) && !found);
  if (found)
    return (p);
  else
    return (0);
}


x86 assembly (clang, -O0):
<checkparm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1160 <checkparm+0x50>
movl   $0x1,-0x20(%rbp)
jmp    1169 <checkparm+0x59>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116e <checkparm+0x5e>
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x8(%rbp),%ecx
mov    %al,-0x21(%rbp)
jge    118b <checkparm+0x7b>
cmpl   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1131 <checkparm+0x21>
cmpl   $0x0,-0x20(%rbp)
je     11ab <checkparm+0x9b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b2 <checkparm+0xa2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkparm>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %edx,%ebx
mov    %edx,%eax
mov    (%r15,%rax,8),%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
mov    %ecx,%edx
add    %ebx,%edx
cmp    %ebp,%edx
jge    1154 <checkparm+0x44>
test   %cl,%cl
jne    1130 <checkparm+0x20>
xor    %ecx,%ecx
test   %rax,%rax
cmove  %edx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @checkparm(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
store i32 0, i32* %9
store i32 0, i32* %8
br label %10
10: ; preds = %32, %3
%11 = load i8**, i8*** %6
%12 = load i32, i32* %8
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %11, i64 %13
%15 = load i8*, i8** %14
%16 = load i8*, i8** %7
%17 = call i64 @strcmp(i8* %15, i8* %16)
%18 = icmp eq i64 0, %17
br i1 %18, label %19, label %20
19: ; preds = %10
store i32 1, i32* %9
br label %23
20: ; preds = %10
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 1
store i32 %22, i32* %8
br label %23
23: ; preds = %20, %19
br label %24
24: ; preds = %23
%25 = load i32, i32* %8
%26 = load i32, i32* %5
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i32, i32* %9
%30 = icmp ne i32 %29, 0
%31 = xor i1 %30, true
br label %32
32: ; preds = %28, %24
%33 = phi i1 [ false, %24 ], [ %31, %28 ]
br i1 %33, label %10, label %34
34: ; preds = %32
%35 = load i32, i32* %9
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = load i32, i32* %8
store i32 %38, i32* %4
br label %40
39: ; preds = %34
store i32 0, i32* %4
br label %40
40: ; preds = %39, %37
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
define i32 @checkparm(i32 %0, i8** nocapture %1, i8* %2) {
br label %4
4: ; preds = %4, %3
%5 = phi i32 [ 0, %3 ], [ %13, %4 ]
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds i8*, i8** %1, i64 %6
%8 = load i8*, i8** %7
%9 = tail call i64 @strcmp(i8* %8, i8* %2)
%10 = icmp eq i64 %9, 0
%11 = xor i1 %10, true
%12 = zext i1 %11 to i32
%13 = add nuw nsw i32 %5, %12
%14 = icmp slt i32 %13, %0
%15 = select i1 %14, i1 %11, i1 false
br i1 %15, label %4, label %16
16: ; preds = %4
%17 = select i1 %10, i32 %13, i32 0
ret i32 %17
}