#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 */
char *strchr(char const *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
long strtoul(char const *, char **, int /*<<< orphan*/);
long x_argument(char c, const char *argument, char *arg) {
  const char *p;
  char *q;
  long number;
  p = strchr(argument, c);
  if (p == NULL) {
    strcpy(arg, argument);
    return 1;
  }
  number = strtoul(argument, &q, 0);
  if (q != p) {
    number = 0;
  }
  strcpy(arg, p + 1);
  return number;
}


x86 assembly (clang, -O0):
<x_argument>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dil,%al
mov    %al,-0x9(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117c <x_argument+0x4c>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
movq   $0x1,-0x8(%rbp)
jmp    11be <x_argument+0x8e>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     11a5 <x_argument+0x75>
movq   $0x0,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<x_argument>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %edi,%esi
mov    %r12,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     1179 <x_argument+0x49>
mov    %rax,%rbx
mov    %rsp,%rsi
xor    %r15d,%r15d
mov    %r12,%rdi
xor    %edx,%edx
call   1050 <strtoul@plt>
cmp    %rbx,(%rsp)
cmove  %rax,%r15
add    $0x1,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
jmp    118a <x_argument+0x5a>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    $0x1,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @x_argument(i8 signext %0, i8* %1, i8* %2) {
%4 = alloca i64
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
store i8 %0, i8* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %6
%12 = load i8, i8* %5
%13 = call i8* @strchr(i8* %11, i8 signext %12)
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i8*, i8** %7
%18 = load i8*, i8** %6
%19 = call i32 @strcpy(i8* %17, i8* %18)
store i64 1, i64* %4
br label %33
20: ; preds = %3
%21 = load i8*, i8** %6
%22 = call i64 @strtoul(i8* %21, i8** %9, i32 0)
store i64 %22, i64* %10
%23 = load i8*, i8** %9
%24 = load i8*, i8** %8
%25 = icmp ne i8* %23, %24
br i1 %25, label %26, label %27
26: ; preds = %20
store i64 0, i64* %10
br label %27
27: ; preds = %26, %20
%28 = load i8*, i8** %7
%29 = load i8*, i8** %8
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = call i32 @strcpy(i8* %28, i8* %30)
%32 = load i64, i64* %10
store i64 %32, i64* %4
br label %33
33: ; preds = %27, %16
%34 = load i64, i64* %4
ret i64 %34
}

LLVM IR (-O2):
define i64 @x_argument(i8 signext %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext %0)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @strcpy(i8* %2, i8* %1)
br label %17
10: ; preds = %3
%11 = call i64 @strtoul(i8* %1, i8** %4, i32 0)
%12 = load i8*, i8** %4
%13 = icmp eq i8* %12, %6
%14 = select i1 %13, i64 %11, i64 0
%15 = getelementptr inbounds i8, i8* %6, i64 1
%16 = tail call i32 @strcpy(i8* %2, i8* %15)
br label %17
17: ; preds = %10, %8
%18 = phi i64 [ 1, %8 ], [ %14, %10 ]
ret i64 %18
}