#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*/ readchar(int);
int sdbd_connect(char *);
char *strstr(char *, char *);
int /*<<< orphan*/ writestring(int, char *);
int sdbd_try(char *url) {
  char *p;
  int sockfd = sdbd_connect(url);
  if (sockfd == -1)
    return -1;
  p = strstr(url, ":url=");
  p += 5;
  writestring(sockfd, p);
  readchar(sockfd);
  return sockfd;
}


x86 assembly (clang, -O0):
<sdbd_try>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sdbd_connect@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    116e <sdbd_try+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a8 <sdbd_try+0x68>
mov    -0x10(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1050 <writestring@plt>
mov    -0x1c(%rbp),%edi
call   1030 <readchar@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sdbd_try>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <sdbd_connect@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1174 <sdbd_try+0x34>
lea    0xea6(%rip),%rsi
mov    %r14,%rdi
call   1060 <strstr@plt>
lea    0x5(%rax),%rsi
mov    %ebx,%edi
call   1050 <writestring@plt>
mov    %ebx,%edi
call   1030 <readchar@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c":url=\00"
define i32 @sdbd_try(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @sdbd_connect(i8* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %22
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i8* @strstr(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 5
store i8* %15, i8** %4
%16 = load i32, i32* %5
%17 = load i8*, i8** %4
%18 = call i32 @writestring(i32 %16, i8* %17)
%19 = load i32, i32* %5
%20 = call i32 @readchar(i32 %19)
%21 = load i32, i32* %5
store i32 %21, i32* %2
br label %22
22: ; preds = %11, %10
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [6 x i8] c":url=\00"
define i32 @sdbd_try(i8* %0) {
%2 = tail call i32 @sdbd_connect(i8* %0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds i8, i8* %5, i64 5
%7 = tail call i32 @writestring(i32 %2, i8* %6)
%8 = tail call i32 @readchar(i32 %2)
br label %9
9: ; preds = %1, %4
ret i32 %2
}