#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*/ time_t;
struct chirp_stat {
  int dummy;
};
struct chirp_client {
  int dummy;
};
typedef int /*<<< orphan*/ safepath;
typedef scalar_t__ int64_t;

/* Variables and functions */
scalar_t__ get_stat_result(struct chirp_client *, char const *,
                           struct chirp_stat *, int /*<<< orphan*/);
scalar_t__ simple_command(struct chirp_client *, int /*<<< orphan*/, char *,
                          char *);
int /*<<< orphan*/ url_encode(char const *, char *, int);
int64_t chirp_client_stat(struct chirp_client *c, const char *path,
                          struct chirp_stat *info, time_t stoptime) {
  char safepath[1024];
  url_encode(path, safepath, sizeof(safepath));
  int64_t result = simple_command(c, stoptime, "stat %s\n", safepath);
  if (result >= 0)
    result = get_stat_result(c, path, info, stoptime);
  return result;
}


x86 assembly (clang, -O0):
<chirp_client_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1050 <url_encode@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x420(%rbp),%rcx
lea    0xe8c(%rip),%rdx
call   1030 <simple_command@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jl     11a9 <chirp_client_stat+0x79>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1040 <get_stat_result@plt>
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chirp_client_stat>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rsp,%r12
mov    %rsi,%rdi
mov    %r12,%rsi
mov    $0x400,%edx
call   1050 <url_encode@plt>
lea    0xe9b(%rip),%rdx
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %r12,%rcx
call   1030 <simple_command@plt>
test   %rax,%rax
js     1189 <chirp_client_stat+0x59>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1040 <get_stat_result@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.chirp_client = type { i32 }
%struct.chirp_stat = type { i32 }
@.str = [9 x i8] c"stat %s\0A\00"
define i64 @chirp_client_stat(%struct.chirp_client* %0, i8* %1, %struct.chirp_stat* %2, i32 %3) {
%5 = alloca %struct.chirp_client*
%6 = alloca i8*
%7 = alloca %struct.chirp_stat*
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = alloca i64
store %struct.chirp_client* %0, %struct.chirp_client** %5
store i8* %1, i8** %6
store %struct.chirp_stat* %2, %struct.chirp_stat** %7
store i32 %3, i32* %8
%11 = load i8*, i8** %6
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%13 = call i32 @url_encode(i8* %11, i8* %12, i32 1024)
%14 = load %struct.chirp_client*, %struct.chirp_client** %5
%15 = load i32, i32* %8
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%17 = call i64 @simple_command(%struct.chirp_client* %14, i32 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %16)
store i64 %17, i64* %10
%18 = load i64, i64* %10
%19 = icmp sge i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %4
%21 = load %struct.chirp_client*, %struct.chirp_client** %5
%22 = load i8*, i8** %6
%23 = load %struct.chirp_stat*, %struct.chirp_stat** %7
%24 = load i32, i32* %8
%25 = call i64 @get_stat_result(%struct.chirp_client* %21, i8* %22, %struct.chirp_stat* %23, i32 %24)
store i64 %25, i64* %10
br label %26
26: ; preds = %20, %4
%27 = load i64, i64* %10
ret i64 %27
}

LLVM IR (-O2):
%struct.chirp_client = type { i32 }
%struct.chirp_stat = type { i32 }
@.str = [9 x i8] c"stat %s\0A\00"
define i64 @chirp_client_stat(%struct.chirp_client* %0, i8* %1, %struct.chirp_stat* %2, i32 %3) {
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = call i32 @url_encode(i8* %1, i8* %6, i32 1024)
%8 = call i64 @simple_command(%struct.chirp_client* %0, i32 %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %6)
%9 = icmp sgt i64 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = call i64 @get_stat_result(%struct.chirp_client* %0, i8* %1, %struct.chirp_stat* %2, i32 %3)
br label %12
12: ; preds = %10, %4
%13 = phi i64 [ %11, %10 ], [ %8, %4 ]
ret i64 %13
}