#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 EINVAL;
int ENOMEM;
char *strchr(char *, char);
scalar_t__ strncmp(char *, char *, int);
char *strndup(char *, int);
int s3_path_uri_pull(const char *path, char **_host, char **_after_host) {
  int ret;
  char *host_start;
  char *host;
  char *s = (char *)path;
  if (strncmp(s, "s3://", sizeof("s3://") - 1) != 0) {
    ret = -EINVAL;
    goto err_out;
  }
  s += (sizeof("s3://") - 1);
  while (*s == '/')
    s++;
  if (*s == '\0') {
    ret = -EINVAL;
    goto err_out;
  }
  host_start = s;
  s = strchr(host_start, '/');
  if (s == NULL) {
    ret = -EINVAL;
    goto err_out;
  }
  host = strndup(host_start, s - host_start);
  if (host == NULL) {
    ret = -ENOMEM;
    goto err_out;
  }
  *_host = host;
  *_after_host = s;
  return 0;
err_out:
  return ret;
}


x86 assembly (clang, -O0):
<s3_path_uri_pull>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xea9(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     117e <s3_path_uri_pull+0x4e>
xor    %eax,%eax
mov    0x2e64(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x24(%rbp)
jmp    1260 <s3_path_uri_pull+0x130>
mov    -0x40(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11ab <s3_path_uri_pull+0x7b>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    118a <s3_path_uri_pull+0x5a>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11ce <s3_path_uri_pull+0x9e>
xor    %eax,%eax
mov    0x2e14(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x24(%rbp)
jmp    1260 <s3_path_uri_pull+0x130>
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1206 <s3_path_uri_pull+0xd6>
xor    %eax,%eax
mov    0x2ddc(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x24(%rbp)
jmp    1260 <s3_path_uri_pull+0x130>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1050 <strndup@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    123e <s3_path_uri_pull+0x10e>
xor    %eax,%eax
mov    0x2dac(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x24(%rbp)
jmp    1260 <s3_path_uri_pull+0x130>
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1266 <s3_path_uri_pull+0x136>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s3_path_uri_pull>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xeb5(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
mov    0x2e7c(%rip),%rbp
test   %rax,%rax
jne    11be <s3_path_uri_pull+0x8e>
lea    0x5(%r12),%rbx
add    $0x5,%r12d
nopw   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
cmp    $0x2f,%al
jne    1181 <s3_path_uri_pull+0x51>
add    $0x1,%rbx
add    $0x1,%r12d
jmp    1170 <s3_path_uri_pull+0x40>
test   %al,%al
je     11be <s3_path_uri_pull+0x8e>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11be <s3_path_uri_pull+0x8e>
mov    %rax,%r13
mov    %r13d,%esi
sub    %r12d,%esi
mov    %rbx,%rdi
call   1050 <strndup@plt>
test   %rax,%rax
je     11b7 <s3_path_uri_pull+0x87>
mov    %rax,(%r15)
mov    %r13,(%r14)
xor    %eax,%eax
jmp    11c3 <s3_path_uri_pull+0x93>
mov    0x2e22(%rip),%rbp
xor    %eax,%eax
sub    0x0(%rbp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"s3://\00"
@EINVAL = global i32 0
@ENOMEM = global i32 0
define i32 @s3_path_uri_pull(i8* %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2) {
%4 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %24
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %0, i64 5
br label %8
8: ; preds = %11, %6
%9 = phi i8* [ %7, %6 ], [ %12, %11 ]
%10 = load i8, i8* %9
switch i8 %10, label %13 [
i8 47, label %11
i8 0, label %24
]
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %9, i64 1
br label %8
13: ; preds = %8
%14 = tail call i8* @strchr(i8* %9, i8 signext 47)
%15 = icmp eq i8* %14, null
br i1 %15, label %24, label %16
16: ; preds = %13
%17 = ptrtoint i8* %14 to i64
%18 = ptrtoint i8* %9 to i64
%19 = sub i64 %17, %18
%20 = trunc i64 %19 to i32
%21 = tail call i8* @strndup(i8* %9, i32 %20)
%22 = icmp eq i8* %21, null
br i1 %22, label %24, label %23
23: ; preds = %16
store i8* %21, i8** %1
store i8* %14, i8** %2
br label %28
24: ; preds = %8, %16, %13, %3
%25 = phi i32* [ @EINVAL, %3 ], [ @EINVAL, %13 ], [ @ENOMEM, %16 ], [ @EINVAL, %8 ]
%26 = load i32, i32* %25
%27 = sub nsw i32 0, %26
br label %28
28: ; preds = %24, %23
%29 = phi i32 [ %27, %24 ], [ 0, %23 ]
ret i32 %29
}