#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 */
struct wbuf {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ wbuf_write(struct wbuf *, char *, int);
int wf_next_argument(char *, int, int /*<<< orphan*/ *);
int wf_parse_filename(struct wbuf *buffer, FILE *fp) {
  int len;
  char filename[4096];
  len = wf_next_argument(filename, sizeof filename, fp);
  if (len == 0) {
    return 0;
  }
  if (!wbuf_write(buffer, filename, len + 1)) {
    return -1;
  }
  return len + 1;
}


x86 assembly (clang, -O0):
<wf_parse_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1000,%esi
call   1030 <wf_next_argument@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1161 <wf_parse_filename+0x41>
movl   $0x0,-0x4(%rbp)
jmp    1195 <wf_parse_filename+0x75>
mov    -0x10(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
call   1040 <wbuf_write@plt>
cmp    $0x0,%eax
jne    118c <wf_parse_filename+0x6c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <wf_parse_filename+0x75>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wf_parse_filename>:
push   %rbp
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%rdx
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x1000,%esi
call   1030 <wf_next_argument@plt>
test   %eax,%eax
je     115b <wf_parse_filename+0x3b>
mov    %eax,%ebp
add    $0x1,%ebp
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <wbuf_write@plt>
cmp    $0x1,%eax
sbb    %eax,%eax
or     %ebp,%eax
jmp    115d <wf_parse_filename+0x3d>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.wbuf = type { i32 }
define i32 @wf_parse_filename(%struct.wbuf* %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.wbuf*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [4096 x i8]
store %struct.wbuf* %0, %struct.wbuf** %4
store i32* %1, i32** %5
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%9 = load i32*, i32** %5
%10 = call i32 @wf_next_argument(i8* %8, i32 4096, i32* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* %3
br label %25
14: ; preds = %2
%15 = load %struct.wbuf*, %struct.wbuf** %4
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
%19 = call i32 @wbuf_write(%struct.wbuf* %15, i8* %16, i32 %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %14
store i32 -1, i32* %3
br label %25
22: ; preds = %14
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %25
25: ; preds = %22, %21, %13
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
%struct.wbuf = type { i32 }
define i32 @wf_parse_filename(%struct.wbuf* %0, i32* %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = call i32 @wf_next_argument(i8* %4, i32 4096, i32* %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = add nsw i32 %5, 1
%9 = call i32 @wbuf_write(%struct.wbuf* %0, i8* %4, i32 %8)
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i32 -1, i32 %8
br label %12
12: ; preds = %7, %2
%13 = phi i32 [ 0, %2 ], [ %11, %7 ]
ret i32 %13
}