#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*/ debug(int, char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
scalar_t__ strchr(char *, char);
char *strsep(char **, char *);
int parse_patch_arg(char *arg, char **str) {
  char *tok, *tok2 = "";
  tok = strsep(str, " ");
  if (!tok)
    return 0;
  if (!*tok == '-') {
    debug(16, "diff_opts parse error: no '-' starting argument: %s", *str);
    return 0;
  }
  if (tok[1] == '-') {
    debug(16, "diff_opts parse_error: long format args not supported");
    return 0;
  }
  if (tok[2] == 0 && strchr("BdDFgiorVxYz", tok[1])) {
    tok2 = strsep(str, " ");
    if (!tok2) {
      debug(16, "diff_opts parse_error: argument %s requires two arguments",
            tok);
      return 0;
    }
  }
  snprintf(arg, 32, "%s%s", tok, tok2);
  return 1;
}


x86 assembly (clang, -O0):
<parse_patch_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1060 <strsep@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1186 <parse_patch_arg+0x46>
movl   $0x0,-0x4(%rbp)
jmp    1290 <parse_patch_arg+0x150>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x2d,%eax
jne    11c6 <parse_patch_arg+0x86>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    $0x10,%edi
lea    0xe4f(%rip),%rsi
mov    $0x0,%al
call   1030 <debug@plt>
movl   $0x0,-0x4(%rbp)
jmp    1290 <parse_patch_arg+0x150>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2d,%eax
jne    11f6 <parse_patch_arg+0xb6>
mov    $0x10,%edi
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1030 <debug@plt>
movl   $0x0,-0x4(%rbp)
jmp    1290 <parse_patch_arg+0x150>
mov    -0x20(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x0,%eax
jne    126c <parse_patch_arg+0x12c>
mov    -0x20(%rbp),%rax
lea    0xe5a(%rip),%rdi
movsbl 0x1(%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     126c <parse_patch_arg+0x12c>
mov    -0x18(%rbp),%rdi
lea    0xdd0(%rip),%rsi
call   1060 <strsep@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1267 <parse_patch_arg+0x127>
mov    -0x20(%rbp),%rdx
mov    $0x10,%edi
lea    0xe25(%rip),%rsi
mov    $0x0,%al
call   1030 <debug@plt>
movl   $0x0,-0x4(%rbp)
jmp    1290 <parse_patch_arg+0x150>
jmp    126c <parse_patch_arg+0x12c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    $0x20,%esi
lea    0xe2f(%rip),%rdx
call   1050 <snprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_patch_arg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xeab(%rip),%rsi
mov    %r15,%rdi
call   1060 <strsep@plt>
test   %rax,%rax
je     1183 <parse_patch_arg+0x43>
mov    %rax,%rbx
mov    0x1(%rax),%al
cmp    $0x2d,%al
jne    1187 <parse_patch_arg+0x47>
lea    0xe8f(%rip),%rsi
xor    %ebp,%ebp
mov    $0x10,%edi
xor    %eax,%eax
call   1030 <debug@plt>
jmp    11b3 <parse_patch_arg+0x73>
xor    %ebp,%ebp
jmp    11b3 <parse_patch_arg+0x73>
lea    0xe73(%rip),%r12
cmpb   $0x0,0x2(%rbx)
je     11be <parse_patch_arg+0x7e>
lea    0xee4(%rip),%rdx
mov    %r14,%rdi
mov    $0x20,%esi
mov    %rbx,%rcx
mov    %r12,%r8
call   1050 <snprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
movsbl %al,%esi
lea    0xe70(%rip),%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     1194 <parse_patch_arg+0x54>
lea    0xe27(%rip),%rsi
mov    %r15,%rdi
call   1060 <strsep@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1194 <parse_patch_arg+0x54>
lea    0xe55(%rip),%rsi
xor    %ebp,%ebp
mov    $0x10,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <debug@plt>
jmp    11b3 <parse_patch_arg+0x73>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c" \00"
@.str.2 = [52 x i8] c"diff_opts parse error: no '-' starting argument: %s\00"
@.str.3 = [54 x i8] c"diff_opts parse_error: long format args not supported\00"
@.str.4 = [13 x i8] c"BdDFgiorVxYz\00"
@.str.5 = [58 x i8] c"diff_opts parse_error: argument %s requires two arguments\00"
@.str.6 = [5 x i8] c"%s%s\00"
define i32 @parse_patch_arg(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = load i8**, i8*** %5
%9 = call i8* @strsep(i8** %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 0, i32* %3
br label %58
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
%17 = xor i1 %16, true
%18 = zext i1 %17 to i32
%19 = icmp eq i32 %18, 45
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = load i8**, i8*** %5
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, ...) @debug(i32 16, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i8* %22)
store i32 0, i32* %3
br label %58
24: ; preds = %13
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 45
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 (i32, i8*, ...) @debug(i32 16, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %58
32: ; preds = %24
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 2
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %53
38: ; preds = %32
%39 = load i8*, i8** %6
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = load i8, i8* %40
%42 = call i64 @strchr(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8 signext %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %53
44: ; preds = %38
%45 = load i8**, i8*** %5
%46 = call i8* @strsep(i8** %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %46, i8** %7
%47 = load i8*, i8** %7
%48 = icmp ne i8* %47, null
br i1 %48, label %52, label %49
49: ; preds = %44
%50 = load i8*, i8** %6
%51 = call i32 (i32, i8*, ...) @debug(i32 16, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i8* %50)
store i32 0, i32* %3
br label %58
52: ; preds = %44
br label %53
53: ; preds = %52, %38, %32
%54 = load i8*, i8** %4
%55 = load i8*, i8** %6
%56 = load i8*, i8** %7
%57 = call i32 @snprintf(i8* %54, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %55, i8* %56)
store i32 1, i32* %3
br label %58
58: ; preds = %53, %49, %30, %20, %12
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c" \00"
@.str.3 = [54 x i8] c"diff_opts parse_error: long format args not supported\00"
@.str.4 = [13 x i8] c"BdDFgiorVxYz\00"
@.str.5 = [58 x i8] c"diff_opts parse_error: argument %s requires two arguments\00"
@.str.6 = [5 x i8] c"%s%s\00"
define i32 @parse_patch_arg(i8* %0, i8** %1) {
%3 = tail call i8* @strsep(i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %26, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 45
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 (i32, i8*, ...) @debug(i32 16, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
br label %26
11: ; preds = %5
%12 = getelementptr inbounds i8, i8* %3, i64 2
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = tail call i64 @strchr(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8 signext %7)
%17 = icmp eq i64 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %15
%19 = tail call i8* @strsep(i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 (i32, i8*, ...) @debug(i32 16, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i8* %3)
br label %26
23: ; preds = %18, %15, %11
%24 = phi i8* [ %19, %18 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %15 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %11 ]
%25 = tail call i32 @snprintf(i8* %0, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %3, i8* %24)
br label %26
26: ; preds = %2, %23, %21, %9
%27 = phi i32 [ 0, %9 ], [ 1, %23 ], [ 0, %21 ], [ 0, %2 ]
ret i32 %27
}