int history_search_pos(string, dir, pos)
char *string;
int dir, pos;
{
  int ret, old;
  old = where_history();
  history_set_pos(pos);
  if (history_search(string, dir) == -1) {
    history_set_pos(old);
    return (-1);
  }
  ret = where_history();
  history_set_pos(old);
  return ret;
}


x86 assembly (clang, -O0):
<history_search_pos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    $0x0,%al
call   1030 <where_history@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
mov    $0x0,%al
call   1050 <history_set_pos@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x0,%al
call   1040 <history_search@plt>
cmp    $0xffffffff,%eax
jne    1183 <history_search_pos+0x53>
mov    -0x20(%rbp),%edi
mov    $0x0,%al
call   1050 <history_set_pos@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119d <history_search_pos+0x6d>
mov    $0x0,%al
call   1030 <where_history@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
mov    $0x0,%al
call   1050 <history_set_pos@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<history_search_pos>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%r15d
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <where_history@plt>
mov    %eax,%r14d
mov    %ebp,%edi
xor    %eax,%eax
call   1050 <history_set_pos@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <history_search@plt>
cmp    $0xffffffff,%eax
je     116f <history_search_pos+0x3f>
xor    %eax,%eax
call   1030 <where_history@plt>
mov    %eax,%ebp
jmp    1174 <history_search_pos+0x44>
mov    $0xffffffff,%ebp
mov    %r14d,%edi
xor    %eax,%eax
call   1050 <history_set_pos@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @history_search_pos(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = call i32 (...) @where_history()
store i32 %10, i32* %9
%11 = load i32, i32* %7
%12 = call i32 (i32, ...) bitcast (i32 (...)* @history_set_pos to i32 (i32, ...)*)(i32 %11)
%13 = load i8*, i8** %5
%14 = load i32, i32* %6
%15 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @history_search to i32 (i8*, i32, ...)*)(i8* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = load i32, i32* %9
%19 = call i32 (i32, ...) bitcast (i32 (...)* @history_set_pos to i32 (i32, ...)*)(i32 %18)
store i32 -1, i32* %4
br label %25
20: ; preds = %3
%21 = call i32 (...) @where_history()
store i32 %21, i32* %8
%22 = load i32, i32* %9
%23 = call i32 (i32, ...) bitcast (i32 (...)* @history_set_pos to i32 (i32, ...)*)(i32 %22)
%24 = load i32, i32* %8
store i32 %24, i32* %4
br label %25
25: ; preds = %20, %17
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
define i32 @history_search_pos(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 (...) @where_history()
%5 = tail call i32 (i32, ...) bitcast (i32 (...)* @history_set_pos to i32 (i32, ...)*)(i32 %2)
%6 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @history_search to i32 (i8*, i32, ...)*)(i8* %0, i32 %1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i32 (...) @where_history()
br label %10
10: ; preds = %3, %8
%11 = phi i32 [ %9, %8 ], [ -1, %3 ]
%12 = tail call i32 (i32, ...) bitcast (i32 (...)* @history_set_pos to i32 (i32, ...)*)(i32 %4)
ret i32 %11
}