#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 atoi_validate(int /*<<< orphan*/, char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
scalar_t__ optind;
int parse_opt(int *argc, char ***argv, int remain, int *workers) {
  int status = 0;
  int opt;
  while ((opt = getopt(*argc, *argv, "p:h")) != -1)
    switch (opt) {
    case 'p':
      if ((*workers = atoi_validate(optarg, "workers")) > 0)
        break;
    case '?':
    case 'h':
      status = -1;
    }
  *argv += optind;
  *argc -= optind;
  return (status || *argc != remain);
}


x86 assembly (clang, -O0):
<parse_opt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xeae(%rip),%rdx
call   1040 <getopt@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
je     11d3 <parse_opt+0xb3>
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x3f,%eax
je     11c7 <parse_opt+0xa7>
jmp    1177 <parse_opt+0x57>
mov    -0x2c(%rbp),%eax
sub    $0x68,%eax
je     11c7 <parse_opt+0xa7>
jmp    1188 <parse_opt+0x68>
mov    -0x2c(%rbp),%eax
sub    $0x70,%eax
jne    11ce <parse_opt+0xae>
jmp    1199 <parse_opt+0x79>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
call   1030 <atoi_validate@plt>
mov    -0x20(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0x0,%eax
jle    11c2 <parse_opt+0xa2>
jmp    11ce <parse_opt+0xae>
jmp    11c7 <parse_opt+0xa7>
movl   $0xffffffff,-0x24(%rbp)
jmp    113e <parse_opt+0x1e>
mov    0x2e06(%rip),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
shl    $0x3,%rcx
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    0x2dee(%rip),%rax
mov    (%rax),%rdx
mov    -0x8(%rbp),%rax
movslq (%rax),%rcx
sub    %rdx,%rcx
mov    %ecx,(%rax)
mov    $0x1,%al
cmpl   $0x0,-0x24(%rbp)
mov    %al,-0x2d(%rbp)
jne    121f <parse_opt+0xff>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
cmp    -0x14(%rbp),%eax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_opt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %edx,0x4(%rsp)
mov    %rsi,%rbp
mov    %rdi,%rbx
xor    %r14d,%r14d
lea    0xebe(%rip),%r12
lea    0xebb(%rip),%r13
mov    %r14d,%eax
mov    %r14b,0x3(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%edi
mov    0x0(%rbp),%rsi
mov    %r12,%rdx
call   1040 <getopt@plt>
mov    $0x1,%r14b
cmp    $0x6f,%eax
jle    11a0 <parse_opt+0x80>
cmp    $0x70,%eax
jne    1160 <parse_opt+0x40>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    %r13,%rsi
call   1030 <atoi_validate@plt>
mov    %eax,(%r15)
test   %eax,%eax
jg     1160 <parse_opt+0x40>
jmp    1149 <parse_opt+0x29>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0xffffffff,%eax
je     11b1 <parse_opt+0x91>
cmp    $0x3f,%eax
je     1149 <parse_opt+0x29>
cmp    $0x68,%eax
jne    1160 <parse_opt+0x40>
jmp    1149 <parse_opt+0x29>
mov    0x2e28(%rip),%rax
mov    (%rax),%rax
lea    0x0(,%rax,8),%rcx
add    %rcx,0x0(%rbp)
mov    (%rbx),%ecx
sub    %eax,%ecx
mov    %ecx,(%rbx)
cmp    0x4(%rsp),%ecx
setne  %al
mov    0x3(%rsp),%cl
or     %al,%cl
movzbl %cl,%eax
and    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"p:h\00"
@optarg = global i32 0
@.str.1 = [8 x i8] c"workers\00"
@optind = global i64 0
define i32 @parse_opt(i32* %0, i8*** %1, i32 %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i8***
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i8*** %1, i8**** %6
store i32 %2, i32* %7
store i32* %3, i32** %8
store i32 0, i32* %9
br label %11
11: ; preds = %28, %4
%12 = load i32*, i32** %5
%13 = load i32, i32* %12
%14 = load i8***, i8**** %6
%15 = load i8**, i8*** %14
%16 = call i32 @getopt(i32 %13, i8** %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %10
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %29
18: ; preds = %11
%19 = load i32, i32* %10
switch i32 %19, label %28 [
i32 112, label %20
i32 63, label %27
i32 104, label %27
]
20: ; preds = %18
%21 = load i32, i32* @optarg
%22 = call i32 @atoi_validate(i32 %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32*, i32** %8
store i32 %22, i32* %23
%24 = icmp sgt i32 %22, 0
br i1 %24, label %25, label %26
25: ; preds = %20
br label %28
26: ; preds = %20
br label %27
27: ; preds = %18, %18, %26
store i32 -1, i32* %9
br label %28
28: ; preds = %27, %18, %25
br label %11
29: ; preds = %11
%30 = load i64, i64* @optind
%31 = load i8***, i8**** %6
%32 = load i8**, i8*** %31
%33 = getelementptr inbounds i8*, i8** %32, i64 %30
store i8** %33, i8*** %31
%34 = load i64, i64* @optind
%35 = load i32*, i32** %5
%36 = load i32, i32* %35
%37 = sext i32 %36 to i64
%38 = sub nsw i64 %37, %34
%39 = trunc i64 %38 to i32
store i32 %39, i32* %35
%40 = load i32, i32* %9
%41 = icmp ne i32 %40, 0
br i1 %41, label %47, label %42
42: ; preds = %29
%43 = load i32*, i32** %5
%44 = load i32, i32* %43
%45 = load i32, i32* %7
%46 = icmp ne i32 %44, %45
br label %47
47: ; preds = %42, %29
%48 = phi i1 [ true, %29 ], [ %46, %42 ]
%49 = zext i1 %48 to i32
ret i32 %49
}

LLVM IR (-O2):
@.str = [4 x i8] c"p:h\00"
@optarg = global i32 0
@.str.1 = [8 x i8] c"workers\00"
@optind = global i64 0
define i32 @parse_opt(i32* nocapture %0, i8*** nocapture %1, i32 %2, i32* nocapture writeonly %3) {
br label %5
5: ; preds = %16, %4
%6 = phi i1 [ true, %16 ], [ false, %4 ]
br label %7
7: ; preds = %11, %5
%8 = load i32, i32* %0
%9 = load i8**, i8*** %1
%10 = tail call i32 @getopt(i32 %8, i8** %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %10, label %11 [
i32 -1, label %17
i32 112, label %12
i32 63, label %16
i32 104, label %16
]
11: ; preds = %7, %12
br label %7
12: ; preds = %7
%13 = load i32, i32* @optarg
%14 = tail call i32 @atoi_validate(i32 %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 %14, i32* %3
%15 = icmp sgt i32 %14, 0
br i1 %15, label %11, label %16
16: ; preds = %7, %7, %12
br label %5
17: ; preds = %7
%18 = load i64, i64* @optind
%19 = load i8**, i8*** %1
%20 = getelementptr inbounds i8*, i8** %19, i64 %18
store i8** %20, i8*** %1
%21 = load i32, i32* %0
%22 = trunc i64 %18 to i32
%23 = sub i32 %21, %22
store i32 %23, i32* %0
%24 = icmp ne i32 %23, %2
%25 = select i1 %6, i1 true, i1 %24
%26 = zext i1 %25 to i32
ret i32 %26
}