#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 */
typedef int /*<<< orphan*/ uint64_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ compose_request(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int parse_reply(size_t, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ recv_result(int, int, char *, size_t *, int const);
int /*<<< orphan*/ send_cmd(int, char *, char *);
int /*<<< orphan*/ stdout;
int get_latest_update(const int timeout, int socket, uint64_t *timestamp) {
  char buf[(8 * 1024)] = {'\0'};
  if (!compose_request(buf)) {
    fprintf(stdout, "Could not compose request\n");
    return 0;
  }
  if (!send_cmd(socket, "%s", buf)) {
    fprintf(stdout, "Could not send request\n");
    return 0;
  }
  size_t count;
  if (!recv_result(socket, sizeof(buf), buf, &count, timeout)) {
    fprintf(stdout, "Could not get reply\n");
    return 0;
  }
  return parse_reply(count, buf, timestamp);
}


x86 assembly (clang, -O0):
<get_latest_update>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x2020(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1030 <memset@plt>
lea    -0x2020(%rbp),%rdi
call   1060 <compose_request@plt>
cmp    $0x0,%eax
jne    11be <get_latest_update+0x5e>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1261 <get_latest_update+0x101>
mov    -0xc(%rbp),%edi
lea    -0x2020(%rbp),%rdx
lea    0xe4c(%rip),%rsi
call   1080 <send_cmd@plt>
cmp    $0x0,%eax
jne    11fe <get_latest_update+0x9e>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1261 <get_latest_update+0x101>
mov    -0xc(%rbp),%edi
lea    -0x2020(%rbp),%rdx
mov    -0x8(%rbp),%r8d
mov    $0x2000,%esi
lea    -0x2028(%rbp),%rcx
call   1070 <recv_result@plt>
cmp    $0x0,%eax
jne    1247 <get_latest_update+0xe7>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1261 <get_latest_update+0x101>
mov    -0x2028(%rbp),%rdi
lea    -0x2020(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <parse_reply@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_latest_update>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2010,%rsp
mov    %rdx,%r14
mov    %esi,%r12d
mov    %edi,%r15d
lea    0x10(%rsp),%rbp
xor    %ebx,%ebx
mov    $0x2000,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
mov    %rbp,%rdi
call   1060 <compose_request@plt>
test   %eax,%eax
je     11e6 <get_latest_update+0x86>
lea    0xe7a(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r12d,%edi
call   1080 <send_cmd@plt>
test   %eax,%eax
je     11fd <get_latest_update+0x9d>
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %r12d,%edi
mov    $0x2000,%esi
mov    %r15d,%r8d
call   1070 <recv_result@plt>
test   %eax,%eax
je     120f <get_latest_update+0xaf>
mov    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r14,%rdx
call   1050 <parse_reply@plt>
mov    %eax,%ebx
jmp    1226 <get_latest_update+0xc6>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1226 <get_latest_update+0xc6>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
jmp    121f <get_latest_update+0xbf>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
call   1040 <fprintf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x2010,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [27 x i8] c"Could not compose request\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [24 x i8] c"Could not send request\0A\00"
@.str.3 = [21 x i8] c"Could not get reply\0A\00"
define i32 @get_latest_update(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [8192 x i8]
%9 = alloca i64
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%10 = bitcast [8192 x i8]* %8 to i8*
%11 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%12 = call i32 @compose_request(i8* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %3
%15 = load i32, i32* @stdout
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %39
17: ; preds = %3
%18 = load i32, i32* %6
%19 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%20 = call i32 @send_cmd(i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %17
%23 = load i32, i32* @stdout
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %39
25: ; preds = %17
%26 = load i32, i32* %6
%27 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%28 = load i32, i32* %5
%29 = call i32 @recv_result(i32 %26, i32 8192, i8* %27, i64* %9, i32 %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %25
%32 = load i32, i32* @stdout
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %39
34: ; preds = %25
%35 = load i64, i64* %9
%36 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%37 = load i32*, i32** %7
%38 = call i32 @parse_reply(i64 %35, i8* %36, i32* %37)
store i32 %38, i32* %4
br label %39
39: ; preds = %34, %31, %22, %14
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [27 x i8] c"Could not compose request\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [24 x i8] c"Could not send request\0A\00"
@.str.3 = [21 x i8] c"Could not get reply\0A\00"
define i32 @get_latest_update(i32 %0, i32 %1, i32* %2) {
%4 = alloca [8192 x i8]
%5 = alloca i64
%6 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%7 = call i32 @compose_request(i8* %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* @stdout
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %30
12: ; preds = %3
%13 = call i32 @send_cmd(i32 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stdout
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %30
18: ; preds = %12
%19 = bitcast i64* %5 to i8*
%20 = call i32 @recv_result(i32 %1, i32 8192, i8* %6, i64* %5, i32 %0)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* @stdout
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %28
25: ; preds = %18
%26 = load i64, i64* %5
%27 = call i32 @parse_reply(i64 %26, i8* %6, i32* %2)
br label %28
28: ; preds = %25, %22
%29 = phi i32 [ %27, %25 ], [ 0, %22 ]
br label %30
30: ; preds = %28, %15, %9
%31 = phi i32 [ %29, %28 ], [ 0, %15 ], [ 0, %9 ]
ret i32 %31
}