#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*/ memcpy(char *, char *, size_t const);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int GetNextURL(char *p, char *q, char *myurl) {
  char *endOfLink = strchr(p, '\n');
  if (endOfLink == NULL) {
    strcpy(myurl, "http://127.0.0.1/");
    return 0;
  } else {
    const size_t length = endOfLink - p;
    memcpy(myurl, p, length);
    myurl[length] = '\0';
    return 1;
  }
}


x86 assembly (clang, -O0):
<GetNextURL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117d <GetNextURL+0x4d>
mov    -0x20(%rbp),%rdi
lea    0xe94(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <GetNextURL+0x80>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetNextURL>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rdi,%r15
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     116a <GetNextURL+0x3a>
mov    %rax,%rbx
sub    %r15,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
movb   $0x0,(%r14,%rbx,1)
mov    $0x1,%eax
jmp    117b <GetNextURL+0x4b>
lea    0xe8f(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"http://127.0.0.1/\00"
define i32 @GetNextURL(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %5
%11 = call i8* @strchr(i8* %10, i8 signext 10)
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i8*, i8** %7
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %30
17: ; preds = %3
%18 = load i8*, i8** %8
%19 = load i8*, i8** %5
%20 = ptrtoint i8* %18 to i64
%21 = ptrtoint i8* %19 to i64
%22 = sub i64 %20, %21
store i64 %22, i64* %9
%23 = load i8*, i8** %7
%24 = load i8*, i8** %5
%25 = load i64, i64* %9
%26 = call i32 @memcpy(i8* %23, i8* %24, i64 %25)
%27 = load i8*, i8** %7
%28 = load i64, i64* %9
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8 0, i8* %29
store i32 1, i32* %4
br label %30
30: ; preds = %17, %14
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
@.str = [18 x i8] c"http://127.0.0.1/\00"
define i32 @GetNextURL(i8* %0, i8* nocapture readnone %1, i8* %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %14
8: ; preds = %3
%9 = ptrtoint i8* %4 to i64
%10 = ptrtoint i8* %0 to i64
%11 = sub i64 %9, %10
%12 = tail call i32 @memcpy(i8* %2, i8* %0, i64 %11)
%13 = getelementptr inbounds i8, i8* %2, i64 %11
store i8 0, i8* %13
br label %14
14: ; preds = %8, %6
%15 = phi i32 [ 0, %6 ], [ 1, %8 ]
ret i32 %15
}