#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 *get_argv(int, char **, int, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int arg_parse_strcpy(int i, int argc, char *argv[], char *buf, int nsz) {
  char *arg = get_argv(argc, argv, i, "string");
  ;
  if (arg) {
    strncpy(buf, arg, nsz);
    buf[nsz - 1] = 0;
  } else {
    buf[0] = 0;
  }
  return arg ? ++i : -1;
}


x86 assembly (clang, -O0):
<arg_parse_strcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%edx
lea    0xeb5(%rip),%rcx
call   1030 <get_argv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1185 <arg_parse_strcpy+0x65>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    118c <arg_parse_strcpy+0x6c>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     11a8 <arg_parse_strcpy+0x88>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    %eax,-0x2c(%rbp)
jmp    11b5 <arg_parse_strcpy+0x95>
mov    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b5 <arg_parse_strcpy+0x95>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arg_parse_strcpy>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %rcx,%r14
mov    %edi,%ebx
lea    0xeca(%rip),%rcx
mov    %esi,%edi
mov    %rdx,%rsi
mov    %ebx,%edx
call   1030 <get_argv@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1162 <arg_parse_strcpy+0x42>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
call   1040 <strncpy@plt>
movslq %r15d,%rax
add    %rax,%r14
add    $0xffffffffffffffff,%r14
movb   $0x0,(%r14)
add    $0x1,%ebx
cmp    $0x1,%rbp
sbb    %eax,%eax
or     %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"string\00"
define i32 @arg_parse_strcpy(i32 %0, i32 %1, i8** %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8** %2, i8*** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%12 = load i32, i32* %7
%13 = load i8**, i8*** %8
%14 = load i32, i32* %6
%15 = call i8* @get_argv(i32 %12, i8** %13, i32 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %11
%16 = load i8*, i8** %11
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %28
18: ; preds = %5
%19 = load i8*, i8** %9
%20 = load i8*, i8** %11
%21 = load i32, i32* %10
%22 = call i32 @strncpy(i8* %19, i8* %20, i32 %21)
%23 = load i8*, i8** %9
%24 = load i32, i32* %10
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
store i8 0, i8* %27
br label %31
28: ; preds = %5
%29 = load i8*, i8** %9
%30 = getelementptr inbounds i8, i8* %29, i64 0
store i8 0, i8* %30
br label %31
31: ; preds = %28, %18
%32 = load i8*, i8** %11
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %38
37: ; preds = %31
br label %38
38: ; preds = %37, %34
%39 = phi i32 [ %36, %34 ], [ -1, %37 ]
ret i32 %39
}

LLVM IR (-O2):
@.str = [7 x i8] c"string\00"
define i32 @arg_parse_strcpy(i32 %0, i32 %1, i8** %2, i8* %3, i32 %4) {
%6 = tail call i8* @get_argv(i32 %1, i8** %2, i32 %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = tail call i32 @strncpy(i8* %3, i8* %6, i32 %4)
%10 = add nsw i32 %4, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %3, i64 %11
br label %13
13: ; preds = %5, %8
%14 = phi i8* [ %12, %8 ], [ %3, %5 ]
store i8 0, i8* %14
%15 = add nsw i32 %0, 1
%16 = select i1 %7, i32 -1, i32 %15
ret i32 %16
}