#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 */
struct walnut_cmd_arg {
  int dummy;
};
struct option {
  char *member_0;
  char member_3;
  int /*<<< orphan*/ *member_2;
  int /*<<< orphan*/ member_1;
};

/* Variables and functions */
int EOF;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getopt_long(int, char **, char *, struct option *, int /*<<< orphan*/ *);
#define no_argument 128
int /*<<< orphan*/ stderr;
int parse_help(int argc, char **argv, struct walnut_cmd_arg *cmd) {
  int c;
  static struct option opts[] = {{"help", no_argument, NULL, 'h'},
                                 {NULL, 0, NULL, 0}};
  static char optc[] = "h";
  while ((c = getopt_long(argc, argv, optc, opts, NULL)) != EOF) {
    switch (c) {
    case 'h':
      return -1;
    default:
      fprintf(stderr, "Invalid command and/or option\n");
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_help>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0x2f3f(%rip),%rdx
lea    0x2ef8(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1030 <getopt_long@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e8c(%rip),%rcx
cmp    (%rcx),%eax
je     11a2 <parse_help+0x82>
mov    -0x1c(%rbp),%eax
sub    $0x68,%eax
jne    1181 <parse_help+0x61>
jmp    1175 <parse_help+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <parse_help+0x89>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <parse_help+0x89>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_help>:
push   %rbx
lea    0x2f58(%rip),%rdx
lea    0x2f11(%rip),%rcx
xor    %ebx,%ebx
xor    %r8d,%r8d
call   1030 <getopt_long@plt>
mov    0x2ea8(%rip),%rcx
cmp    (%rcx),%eax
je     1163 <parse_help+0x43>
mov    $0xffffffff,%ebx
cmp    $0x68,%eax
je     1163 <parse_help+0x43>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    0xea7(%rip),%rsi
call   1040 <fprintf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32*, i32 }
%struct.walnut_cmd_arg = type { i32 }
@parse_help.opts = internal global [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8 -128, i32* null, i32 104 }, %struct.option zeroinitializer]
@.str = [5 x i8] c"help\00"
@parse_help.optc = internal global [2 x i8] c"h\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"Invalid command and/or option\0A\00"
define i32 @parse_help(i32 %0, i8** %1, %struct.walnut_cmd_arg* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca %struct.walnut_cmd_arg*
%8 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store %struct.walnut_cmd_arg* %2, %struct.walnut_cmd_arg** %7
br label %9
9: ; preds = %3
%10 = load i32, i32* %5
%11 = load i8**, i8*** %6
%12 = call i32 @getopt_long(i32 %10, i8** %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @parse_help.optc, i64 0, i64 0), %struct.option* getelementptr inbounds ([2 x %struct.option], [2 x %struct.option]* @parse_help.opts, i64 0, i64 0), i32* null)
store i32 %12, i32* %8
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %21
15: ; preds = %9
%16 = load i32, i32* %8
switch i32 %16, label %18 [
i32 104, label %17
]
17: ; preds = %15
store i32 -1, i32* %4
br label %22
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %22
21: ; preds = %9
store i32 0, i32* %4
br label %22
22: ; preds = %21, %18, %17
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32*, i32 }
%struct.walnut_cmd_arg = type { i32 }
@parse_help.opts = internal global [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8 -128, i32* null, i32 104 }, %struct.option zeroinitializer]
@.str = [5 x i8] c"help\00"
@parse_help.optc = internal global [2 x i8] c"h\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"Invalid command and/or option\0A\00"
define i32 @parse_help(i32 %0, i8** %1, %struct.walnut_cmd_arg* nocapture readnone %2) {
%4 = tail call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @parse_help.optc, i64 0, i64 0), %struct.option* getelementptr inbounds ([2 x %struct.option], [2 x %struct.option]* @parse_help.opts, i64 0, i64 0), i32* null)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = icmp eq i32 %4, 104
br i1 %8, label %12, label %9
9: ; preds = %7
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %3, %7, %9
%13 = phi i32 [ -1, %9 ], [ -1, %7 ], [ 0, %3 ]
ret i32 %13
}