#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int dbd_get_target_obj(char *argv, char *obj) {
  char obj_cmd[] = "-o";
  int index = strstr(argv, obj_cmd) - argv;
  if (index < 0) {
    fprintf(stderr, "Can't not fidn obj from\n%s\n", argv);
    return -1;
  }
  index += strlen(obj_cmd) + 1;
  int n = strchr(argv + index, ' ') - argv - index;
  strncpy(obj, argv + index, n);
  return 0;
}


x86 assembly (clang, -O0):
<dbd_get_target_obj>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0xe99(%rip),%ax
mov    %ax,-0x1b(%rbp)
mov    0xe91(%rip),%al
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1b(%rbp),%rsi
call   1070 <strstr@plt>
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11ba <dbd_get_target_obj+0x6a>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe5a(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1218 <dbd_get_target_obj+0xc8>
lea    -0x1b(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
add    $0x1,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
movslq -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbd_get_target_obj>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeab(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,%rbx
sub    %r15,%rbx
test   $0x80000000,%ebx
jne    1198 <dbd_get_target_obj+0x58>
lea    0x3(%rbx),%eax
movslq %eax,%r12
add    %r15,%r12
mov    %r12,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
lea    (%rbx,%r15,1),%ecx
add    $0x3,%ecx
sub    %ecx,%eax
mov    %r14,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
jmp    11b5 <dbd_get_target_obj+0x75>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.dbd_get_target_obj.obj_cmd = [3 x i8] c"-o\00"
@stderr = global i32 0
@.str = [28 x i8] c"Can't not fidn obj from\0A%s\0A\00"
define i32 @dbd_get_target_obj(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [3 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = bitcast [3 x i8]* %6 to i8*
%10 = load i8*, i8** %4
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%12 = call i8* @strstr(i8* %10, i8* %11)
%13 = load i8*, i8** %4
%14 = ptrtoint i8* %12 to i64
%15 = ptrtoint i8* %13 to i64
%16 = sub i64 %14, %15
%17 = trunc i64 %16 to i32
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %4
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %22)
store i32 -1, i32* %3
br label %52
24: ; preds = %2
%25 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%26 = call i64 @strlen(i8* %25)
%27 = add nsw i64 %26, 1
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = add nsw i64 %29, %27
%31 = trunc i64 %30 to i32
store i32 %31, i32* %7
%32 = load i8*, i8** %4
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = call i8* @strchr(i8* %35, i8 signext 32)
%37 = load i8*, i8** %4
%38 = ptrtoint i8* %36 to i64
%39 = ptrtoint i8* %37 to i64
%40 = sub i64 %38, %39
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = sub nsw i64 %40, %42
%44 = trunc i64 %43 to i32
store i32 %44, i32* %8
%45 = load i8*, i8** %5
%46 = load i8*, i8** %4
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i32, i32* %8
%51 = call i32 @strncpy(i8* %45, i8* %49, i32 %50)
store i32 0, i32* %3
br label %52
52: ; preds = %24, %20
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@__const.dbd_get_target_obj.obj_cmd = [3 x i8] c"-o\00"
@stderr = global i32 0
@.str = [28 x i8] c"Can't not fidn obj from\0A%s\0A\00"
define i32 @dbd_get_target_obj(i8* %0, i8* %1) {
%3 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @__const.dbd_get_target_obj.obj_cmd, i64 0, i64 0))
%4 = ptrtoint i8* %3 to i64
%5 = ptrtoint i8* %0 to i64
%6 = sub i64 %4, %5
%7 = and i64 %6, 2147483648
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %23
12: ; preds = %2
%13 = shl i64 %6, 32
%14 = add i64 %13, 12884901888
%15 = ashr exact i64 %14, 32
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = tail call i8* @strchr(i8* dereferenceable(1) %16, i8 signext 32)
%18 = ptrtoint i8* %17 to i64
%19 = add i64 %15, %5
%20 = sub i64 %18, %19
%21 = trunc i64 %20 to i32
%22 = tail call i32 @strncpy(i8* %1, i8* %16, i32 %21)
br label %23
23: ; preds = %12, %9
%24 = phi i32 [ -1, %9 ], [ 0, %12 ]
ret i32 %24
}