#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*/ client_cmd(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int client_connect(char *, char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ getmyaddr(char *);
int /*<<< orphan*/ upload_daemon();
void client_start() {
  char me[64];
  int cfd;
  getmyaddr(me);
  if ((cfd = client_connect(me, "40000")) < 0) {
    if (fork() == 0) {
      upload_daemon();
      exit(0);
    }
    while ((cfd = client_connect(me, "40000")) < 0)
      continue;
    close(cfd);
    client_cmd(1, NULL, NULL);
  } else {
    close(cfd);
  }
}


x86 assembly (clang, -O0):
<client_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x40(%rbp),%rdi
call   1030 <getmyaddr@plt>
lea    -0x40(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1060 <client_connect@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
jge    1200 <client_start+0x90>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
jne    11bc <client_start+0x4c>
mov    $0x0,%al
call   1070 <upload_daemon@plt>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    11c1 <client_start+0x51>
lea    -0x40(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1060 <client_connect@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
jge    11e2 <client_start+0x72>
jmp    11c1 <client_start+0x51>
mov    -0x44(%rbp),%edi
call   1050 <close@plt>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1040 <client_cmd@plt>
jmp    1208 <client_start+0x98>
mov    -0x44(%rbp),%edi
call   1050 <close@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_start>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <getmyaddr@plt>
lea    0xe77(%rip),%rsi
mov    %rbx,%rdi
call   1060 <client_connect@plt>
test   %eax,%eax
js     119e <client_start+0x2e>
mov    %eax,%edi
call   1050 <close@plt>
jmp    11e4 <client_start+0x74>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     11ec <client_start+0x7c>
lea    0xe4f(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <client_connect@plt>
test   %eax,%eax
js     11c0 <client_start+0x50>
mov    %eax,%edi
call   1050 <close@plt>
mov    $0x1,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <client_cmd@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1070 <upload_daemon@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"40000\00"
define void @client_start() {
%1 = alloca [64 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%4 = call i32 @getmyaddr(i8* %3)
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%6 = call i32 @client_connect(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %6, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %0
%9 = call i64 (...) @fork()
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = call i32 (...) @upload_daemon()
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %8
br label %15
15: ; preds = %19, %14
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%17 = call i32 @client_connect(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %17, i32* %2
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
br label %15
20: ; preds = %15
%21 = load i32, i32* %2
%22 = call i32 @close(i32 %21)
%23 = call i32 @client_cmd(i32 1, i32* null, i32* null)
br label %27
24: ; preds = %0
%25 = load i32, i32* %2
%26 = call i32 @close(i32 %25)
br label %27
27: ; preds = %24, %20
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"40000\00"
define void @client_start() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = call i32 @getmyaddr(i8* %2)
%4 = call i32 @client_connect(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %18
6: ; preds = %0
%7 = call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = call i32 (...) @upload_daemon()
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %6, %12
%13 = call i32 @client_connect(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%14 = icmp slt i32 %13, 0
br i1 %14, label %12, label %15
15: ; preds = %12
%16 = call i32 @close(i32 %13)
%17 = call i32 @client_cmd(i32 1, i32* null, i32* null)
br label %20
18: ; preds = %0
%19 = call i32 @close(i32 %4)
br label %20
20: ; preds = %18, %15
ret void
}