#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 */
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
void extract_path(const char *req, ssize_t size, char *path, size_t path_size) {
  int path_len;
  int i;
  int ch;
  path_len = 0;
  for (i = 0; i < size; i++) {
    ch = req[i];
    if (path_len >= path_size) {
      fprintf(stderr, "Path length too long\n");
      abort();
    }
    if (ch == ' ') {
      break;
    }
    path[path_len++] = ch;
  }
  path[path_len] = '\0';
}


x86 assembly (clang, -O0):
<extract_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c1 <extract_path+0xa1>
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x2c(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     118a <extract_path+0x6a>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
cmpl   $0x20,-0x2c(%rbp)
jne    1199 <extract_path+0x79>
jmp    11c1 <extract_path+0xa1>
mov    -0x2c(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1145 <extract_path+0x25>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_path>:
push   %rax
test   %esi,%esi
jle    1151 <extract_path+0x31>
mov    %esi,%esi
xor    %eax,%eax
nopl   0x0(%rax)
cmp    %rax,%rcx
je     115b <extract_path+0x3b>
movzbl (%rdi,%rax,1),%r8d
cmp    $0x20,%r8b
je     1153 <extract_path+0x33>
mov    %r8b,(%rdx,%rax,1)
add    $0x1,%rax
cmp    %rax,%rsi
jne    1130 <extract_path+0x10>
mov    %esi,%eax
jmp    1153 <extract_path+0x33>
xor    %eax,%eax
mov    %eax,%eax
movb   $0x0,(%rdx,%rax,1)
pop    %rax
ret
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Path length too long\0A\00"
define void @extract_path(i8* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %12
12: ; preds = %43, %4
%13 = load i32, i32* %10
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %46
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = load i32, i32* %10
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
store i32 %22, i32* %11
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = load i64, i64* %8
%26 = icmp uge i64 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %16
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%30 = call i32 (...) @abort()
unreachable
31: ; preds = %16
%32 = load i32, i32* %11
%33 = icmp eq i32 %32, 32
br i1 %33, label %34, label %35
34: ; preds = %31
br label %46
35: ; preds = %31
%36 = load i32, i32* %11
%37 = trunc i32 %36 to i8
%38 = load i8*, i8** %7
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds i8, i8* %38, i64 %41
store i8 %37, i8* %42
br label %43
43: ; preds = %35
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
br label %12
46: ; preds = %34, %12
%47 = load i8*, i8** %7
%48 = load i32, i32* %9
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 0, i8* %50
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Path length too long\0A\00"
define void @extract_path(i8* nocapture %0, i32 %1, i8* nocapture writeonly %2, i64 %3) {
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %25
6: ; preds = %4
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %19
%9 = phi i64 [ 0, %6 ], [ %20, %19 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i64 %9, %3
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 (...) @abort()
unreachable
17: ; preds = %8
%18 = icmp eq i8 %11, 32
br i1 %18, label %23, label %19
19: ; preds = %17
%20 = add nuw nsw i64 %9, 1
%21 = getelementptr inbounds i8, i8* %2, i64 %9
store i8 %11, i8* %21
%22 = icmp eq i64 %20, %7
br i1 %22, label %25, label %8
23: ; preds = %17
%24 = trunc i64 %9 to i32
br label %25
25: ; preds = %19, %23, %4
%26 = phi i32 [ 0, %4 ], [ %24, %23 ], [ %1, %19 ]
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %2, i64 %27
store i8 0, i8* %28
ret void
}