#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*/ wint_t;
struct pane {
  int dummy;
};
struct mark {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ WEOF;
int /*<<< orphan*/ doc_next(struct pane *, struct mark *);
int /*<<< orphan*/ doc_prev(struct pane *, struct mark *);
wint_t doc_move(struct pane *p, struct mark *m, int n) {
  wint_t wc = WEOF;
  while (n < 0 && (wc = doc_prev(p, m)) != WEOF)
    n += 1;
  while (n > 0 && (wc = doc_next(p, m)) != WEOF)
    n -= 1;
  return wc;
}


x86 assembly (clang, -O0):
<doc_move>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x19(%rbp)
jge    116d <doc_move+0x4d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <doc_prev@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    117d <doc_move+0x5d>
jmp    118b <doc_move+0x6b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113f <doc_move+0x1f>
jmp    1190 <doc_move+0x70>
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x1a(%rbp)
jle    11be <doc_move+0x9e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <doc_next@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e2a(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    11ce <doc_move+0xae>
jmp    11dc <doc_move+0xbc>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1190 <doc_move+0x70>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doc_move>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2ea9(%rip),%r12
test   %edx,%edx
js     1170 <doc_move+0x50>
mov    (%r12),%eax
test   %ebx,%ebx
jle    1185 <doc_move+0x65>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <doc_next@plt>
cmp    (%r12),%eax
je     1185 <doc_move+0x65>
lea    -0x1(%rbx),%ecx
cmp    $0x1,%ebx
mov    %ecx,%ebx
jg     1150 <doc_move+0x30>
jmp    1185 <doc_move+0x65>
nopl   (%rax)
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <doc_prev@plt>
cmp    (%r12),%eax
je     113f <doc_move+0x1f>
inc    %ebx
jne    1170 <doc_move+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.pane = type { i32 }
%struct.mark = type { i32 }
@WEOF = global i32 0
define i32 @doc_move(%struct.pane* %0, %struct.mark* %1, i32 %2) {
%4 = alloca %struct.pane*
%5 = alloca %struct.mark*
%6 = alloca i32
%7 = alloca i32
store %struct.pane* %0, %struct.pane** %4
store %struct.mark* %1, %struct.mark** %5
store i32 %2, i32* %6
%8 = load i32, i32* @WEOF
store i32 %8, i32* %7
br label %9
9: ; preds = %20, %3
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = load %struct.pane*, %struct.pane** %4
%14 = load %struct.mark*, %struct.mark** %5
%15 = call i32 @doc_prev(%struct.pane* %13, %struct.mark* %14)
store i32 %15, i32* %7
%16 = load i32, i32* @WEOF
%17 = icmp ne i32 %15, %16
br label %18
18: ; preds = %12, %9
%19 = phi i1 [ false, %9 ], [ %17, %12 ]
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
br label %9
23: ; preds = %18
br label %24
24: ; preds = %35, %23
%25 = load i32, i32* %6
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %24
%28 = load %struct.pane*, %struct.pane** %4
%29 = load %struct.mark*, %struct.mark** %5
%30 = call i32 @doc_next(%struct.pane* %28, %struct.mark* %29)
store i32 %30, i32* %7
%31 = load i32, i32* @WEOF
%32 = icmp ne i32 %30, %31
br label %33
33: ; preds = %27, %24
%34 = phi i1 [ false, %24 ], [ %32, %27 ]
br i1 %34, label %35, label %38
35: ; preds = %33
%36 = load i32, i32* %6
%37 = sub nsw i32 %36, 1
store i32 %37, i32* %6
br label %24
38: ; preds = %33
%39 = load i32, i32* %7
ret i32 %39
}

LLVM IR (-O2):
%struct.pane = type { i32 }
%struct.mark = type { i32 }
@WEOF = global i32 0
define i32 @doc_move(%struct.pane* %0, %struct.mark* %1, i32 %2) {
%4 = load i32, i32* @WEOF
%5 = icmp slt i32 %2, 0
br i1 %5, label %6, label %14
6: ; preds = %3, %11
%7 = phi i32 [ %12, %11 ], [ %2, %3 ]
%8 = tail call i32 @doc_prev(%struct.pane* %0, %struct.mark* %1)
%9 = load i32, i32* @WEOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = add i32 %7, 1
%13 = icmp eq i32 %12, 0
br i1 %13, label %26, label %6
14: ; preds = %6, %3
%15 = phi i32 [ %2, %3 ], [ %7, %6 ]
%16 = phi i32 [ %4, %3 ], [ %8, %6 ]
%17 = icmp sgt i32 %15, 0
br i1 %17, label %18, label %26
18: ; preds = %14, %18
%19 = phi i32 [ %23, %18 ], [ %15, %14 ]
%20 = tail call i32 @doc_next(%struct.pane* %0, %struct.mark* %1)
%21 = load i32, i32* @WEOF
%22 = icmp ne i32 %20, %21
%23 = add nsw i32 %19, -1
%24 = icmp sgt i32 %19, 1
%25 = select i1 %22, i1 %24, i1 false
br i1 %25, label %18, label %26
26: ; preds = %11, %18, %14
%27 = phi i32 [ %16, %14 ], [ %20, %18 ], [ %8, %11 ]
ret i32 %27
}