#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 strlen(char *);
char *strndup(char *, int);
char *strstr(char *, char *);
char *tftpHost(char *URL) {
  char *host = URL + strlen("tftp://");
  char *slash = strstr(host, "/");
  if (slash) {
    return strndup(host, slash - host);
  } else {
    return NULL;
  }
}


x86 assembly (clang, -O0):
<tftpHost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xeb5(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     119e <tftpHost+0x6e>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1040 <strndup@plt>
mov    %rax,-0x8(%rbp)
jmp    11a6 <tftpHost+0x76>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tftpHost>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xec2(%rip),%rdi
call   1030 <strlen@plt>
movslq %eax,%rbx
add    %r14,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     116e <tftpHost+0x3e>
sub    %ebx,%eax
mov    %rbx,%rdi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <strndup@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"tftp://\00"
@.str.1 = [2 x i8] c"/\00"
define i8* @tftpHost(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = call i8* @strstr(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %23
14: ; preds = %1
%15 = load i8*, i8** %4
%16 = load i8*, i8** %5
%17 = load i8*, i8** %4
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = trunc i64 %20 to i32
%22 = call i8* @strndup(i8* %15, i32 %21)
store i8* %22, i8** %2
br label %24
23: ; preds = %1
store i8* null, i8** %2
br label %24
24: ; preds = %23, %14
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
@.str = [8 x i8] c"tftp://\00"
define noalias i8* @tftpHost(i8* %0) {
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = tail call i8* @strchr(i8* dereferenceable(1) %4, i32 47)
%6 = icmp eq i8* %5, null
br i1 %6, label %13, label %7
7: ; preds = %1
%8 = ptrtoint i8* %5 to i64
%9 = ptrtoint i8* %4 to i64
%10 = sub i64 %8, %9
%11 = trunc i64 %10 to i32
%12 = tail call i8* @strndup(i8* %4, i32 %11)
br label %13
13: ; preds = %1, %7
%14 = phi i8* [ %12, %7 ], [ null, %1 ]
ret i8* %14
}