#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 _sarg_argv_add_arg(char *, char const *, int, char **, int *);
int _sarg_argv_resize(char ***, int *);
char *_sarg_trim(char *);
char *strchr(char *, char);
int strlen(char const *);
int _sarg_argv_add_from_line(const char *line, char ***argv, int *argc,
                             int *currarg) {
  int diff, ret, arglen;
  char *sep;
  diff = *argc - *currarg;
  if (diff < 2) {
    ret = _sarg_argv_resize(argv, argc);
    if (ret != 0)
      return ret;
  }
  sep = strchr((char *)line, ' ');
  arglen = strlen(line) + 2;
  if (sep)
    arglen -= strlen(sep);
  ret = _sarg_argv_add_arg("-%s", line, arglen, *argv, currarg);
  if (ret != 0)
    return ret;
  if (sep) {
    sep = _sarg_trim(sep);
    arglen = strlen(sep) + 1;
    _sarg_argv_add_arg("%s", sep, arglen, *argv, currarg);
    if (ret != 0)
      return ret;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_sarg_argv_add_from_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    -0x28(%rbp),%rcx
sub    (%rcx),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x2,-0x2c(%rbp)
jge    11ab <_sarg_argv_add_from_line+0x5b>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <_sarg_argv_resize@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     11a6 <_sarg_argv_add_from_line+0x56>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1286 <_sarg_argv_add_from_line+0x136>
jmp    11ab <_sarg_argv_add_from_line+0x5b>
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x2,%eax
mov    %eax,-0x34(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     11ea <_sarg_argv_add_from_line+0x9a>
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    -0x28(%rbp),%r8
lea    0xdfd(%rip),%rdi
call   1060 <_sarg_argv_add_arg@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     1220 <_sarg_argv_add_from_line+0xd0>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1286 <_sarg_argv_add_from_line+0x136>
cmpq   $0x0,-0x40(%rbp)
je     127f <_sarg_argv_add_from_line+0x12f>
mov    -0x40(%rbp),%rdi
call   1030 <_sarg_trim@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x40(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    -0x28(%rbp),%r8
lea    0xda1(%rip),%rdi
call   1060 <_sarg_argv_add_arg@plt>
cmpl   $0x0,-0x30(%rbp)
je     127a <_sarg_argv_add_from_line+0x12a>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1286 <_sarg_argv_add_from_line+0x136>
jmp    127f <_sarg_argv_add_from_line+0x12f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_sarg_argv_add_from_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdx),%eax
sub    (%rcx),%eax
cmp    $0x1,%eax
jg     1179 <_sarg_argv_add_from_line+0x29>
mov    %r14,%rdi
mov    %rdx,%rsi
call   1070 <_sarg_argv_resize@plt>
test   %eax,%eax
jne    11f2 <_sarg_argv_add_from_line+0xa2>
mov    %rbx,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
add    $0x2,%ebp
test   %r12,%r12
je     11a5 <_sarg_argv_add_from_line+0x55>
mov    %r12,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
mov    (%r14),%rcx
lea    0xe51(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %r15,%r8
call   1060 <_sarg_argv_add_arg@plt>
test   %eax,%eax
jne    11f2 <_sarg_argv_add_from_line+0xa2>
test   %r12,%r12
je     11f2 <_sarg_argv_add_from_line+0xa2>
mov    %r12,%rdi
call   1030 <_sarg_trim@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    (%r14),%rcx
lea    0xe1c(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%r8
call   1060 <_sarg_argv_add_arg@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"-%s\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @_sarg_argv_add_from_line(i8* %0, i8*** %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8***
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i8* %0, i8** %6
store i8*** %1, i8**** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%14 = load i32*, i32** %8
%15 = load i32, i32* %14
%16 = load i32*, i32** %9
%17 = load i32, i32* %16
%18 = sub nsw i32 %15, %17
store i32 %18, i32* %10
%19 = load i32, i32* %10
%20 = icmp slt i32 %19, 2
br i1 %20, label %21, label %30
21: ; preds = %4
%22 = load i8***, i8**** %7
%23 = load i32*, i32** %8
%24 = call i32 @_sarg_argv_resize(i8*** %22, i32* %23)
store i32 %24, i32* %11
%25 = load i32, i32* %11
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = load i32, i32* %11
store i32 %28, i32* %5
br label %75
29: ; preds = %21
br label %30
30: ; preds = %29, %4
%31 = load i8*, i8** %6
%32 = call i8* @strchr(i8* %31, i8 signext 32)
store i8* %32, i8** %13
%33 = load i8*, i8** %6
%34 = call i32 @strlen(i8* %33)
%35 = add nsw i32 %34, 2
store i32 %35, i32* %12
%36 = load i8*, i8** %13
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %43
38: ; preds = %30
%39 = load i8*, i8** %13
%40 = call i32 @strlen(i8* %39)
%41 = load i32, i32* %12
%42 = sub nsw i32 %41, %40
store i32 %42, i32* %12
br label %43
43: ; preds = %38, %30
%44 = load i8*, i8** %6
%45 = load i32, i32* %12
%46 = load i8***, i8**** %7
%47 = load i8**, i8*** %46
%48 = load i32*, i32** %9
%49 = call i32 @_sarg_argv_add_arg(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %44, i32 %45, i8** %47, i32* %48)
store i32 %49, i32* %11
%50 = load i32, i32* %11
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %43
%53 = load i32, i32* %11
store i32 %53, i32* %5
br label %75
54: ; preds = %43
%55 = load i8*, i8** %13
%56 = icmp ne i8* %55, null
br i1 %56, label %57, label %74
57: ; preds = %54
%58 = load i8*, i8** %13
%59 = call i8* @_sarg_trim(i8* %58)
store i8* %59, i8** %13
%60 = load i8*, i8** %13
%61 = call i32 @strlen(i8* %60)
%62 = add nsw i32 %61, 1
store i32 %62, i32* %12
%63 = load i8*, i8** %13
%64 = load i32, i32* %12
%65 = load i8***, i8**** %7
%66 = load i8**, i8*** %65
%67 = load i32*, i32** %9
%68 = call i32 @_sarg_argv_add_arg(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %63, i32 %64, i8** %66, i32* %67)
%69 = load i32, i32* %11
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %57
%72 = load i32, i32* %11
store i32 %72, i32* %5
br label %75
73: ; preds = %57
br label %74
74: ; preds = %73, %54
store i32 0, i32* %5
br label %75
75: ; preds = %74, %71, %52, %27
%76 = load i32, i32* %5
ret i32 %76
}

LLVM IR (-O2):
@.str = [4 x i8] c"-%s\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @_sarg_argv_add_from_line(i8* %0, i8*** %1, i32* %2, i32* %3) {
%5 = load i32, i32* %2
%6 = load i32, i32* %3
%7 = sub nsw i32 %5, %6
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = tail call i32 @_sarg_argv_resize(i8*** %1, i32* %2)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %32
12: ; preds = %9, %4
%13 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 32)
%14 = tail call i32 @strlen(i8* %0)
%15 = add nsw i32 %14, 2
%16 = icmp eq i8* %13, null
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = tail call i32 @strlen(i8* %13)
%19 = sub nsw i32 %15, %18
br label %20
20: ; preds = %17, %12
%21 = phi i32 [ %19, %17 ], [ %15, %12 ]
%22 = load i8**, i8*** %1
%23 = tail call i32 @_sarg_argv_add_arg(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %21, i8** %22, i32* %3)
%24 = icmp ne i32 %23, 0
%25 = select i1 %24, i1 true, i1 %16
br i1 %25, label %32, label %26
26: ; preds = %20
%27 = tail call i8* @_sarg_trim(i8* %13)
%28 = tail call i32 @strlen(i8* %27)
%29 = add nsw i32 %28, 1
%30 = load i8**, i8*** %1
%31 = tail call i32 @_sarg_argv_add_arg(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %27, i32 %29, i8** %30, i32* %3)
br label %32
32: ; preds = %20, %26, %9
%33 = phi i32 [ %10, %9 ], [ %23, %20 ], [ 0, %26 ]
ret i32 %33
}