#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*/ va_list;
struct davici_response {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int davici_get_value_str(struct davici_response *, char *, int);
int vsscanf(char *, char const *, int /*<<< orphan*/);
int davici_value_vscanf(struct davici_response *res, const char *fmt,
                        va_list args) {
  char buf[1024];
  int err;
  err = davici_get_value_str(res, buf, sizeof(buf));
  if (err < 0) {
    return err;
  }
  return vsscanf(buf, fmt, args);
}


x86 assembly (clang, -O0):
<davici_value_vscanf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1030 <davici_get_value_str@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
jge    116c <davici_value_vscanf+0x4c>
mov    -0x424(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1182 <davici_value_vscanf+0x62>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <vsscanf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<davici_value_vscanf>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rsp,%rsi
mov    $0x400,%edx
call   1030 <davici_get_value_str@plt>
test   %eax,%eax
js     114c <davici_value_vscanf+0x2c>
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <vsscanf@plt>
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.davici_response = type { i32 }
define i32 @davici_value_vscanf(%struct.davici_response* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.davici_response*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca i32
store %struct.davici_response* %0, %struct.davici_response** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load %struct.davici_response*, %struct.davici_response** %5
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%12 = call i32 @davici_get_value_str(%struct.davici_response* %10, i8* %11, i32 1024)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* %9
store i32 %16, i32* %4
br label %22
17: ; preds = %3
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%19 = load i8*, i8** %6
%20 = load i32, i32* %7
%21 = call i32 @vsscanf(i8* %18, i8* %19, i32 %20)
store i32 %21, i32* %4
br label %22
22: ; preds = %17, %15
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
%struct.davici_response = type { i32 }
define i32 @davici_value_vscanf(%struct.davici_response* %0, i8* %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = call i32 @davici_get_value_str(%struct.davici_response* %0, i8* %5, i32 1024)
%7 = icmp slt i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = call i32 @vsscanf(i8* %5, i8* %1, i32 %2)
br label %10
10: ; preds = %3, %8
%11 = phi i32 [ %9, %8 ], [ %6, %3 ]
ret i32 %11
}