#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 editor {
  int dummy;
};

/* Variables and functions */
int get(struct editor *, int);
int prev_line(struct editor *ed, int pos) {
  if (pos == 0)
    return -1;
  while (pos > 0) {
    int ch = get(ed, --pos);
    if (ch == '\n')
      break;
  }
  while (pos > 0) {
    int ch = get(ed, --pos);
    if (ch == '\n')
      return pos + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<prev_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1135 <prev_line+0x25>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <prev_line+0xa5>
jmp    113a <prev_line+0x2a>
cmpl   $0x0,-0x14(%rbp)
jle    116d <prev_line+0x5d>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0xffffffff,%esi
mov    %esi,-0x14(%rbp)
call   1030 <get@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jne    1168 <prev_line+0x58>
jmp    116d <prev_line+0x5d>
jmp    113a <prev_line+0x2a>
jmp    1172 <prev_line+0x62>
cmpl   $0x0,-0x14(%rbp)
jle    11ae <prev_line+0x9e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0xffffffff,%esi
mov    %esi,-0x14(%rbp)
call   1030 <get@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jne    11a9 <prev_line+0x99>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11b5 <prev_line+0xa5>
jmp    1172 <prev_line+0x62>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prev_line>:
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
je     115a <prev_line+0x4a>
mov    %esi,%ebx
mov    %rdi,%r14
nopl   (%rax)
test   %ebx,%ebx
jle    1152 <prev_line+0x42>
add    $0xffffffff,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <get@plt>
cmp    $0xa,%eax
jne    1120 <prev_line+0x10>
jmp    1152 <prev_line+0x42>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <get@plt>
cmp    $0xa,%eax
je     1161 <prev_line+0x51>
test   %ebx,%ebx
jg     1140 <prev_line+0x30>
xor    %ebx,%ebx
jmp    1164 <prev_line+0x54>
mov    $0xffffffff,%ebx
jmp    1164 <prev_line+0x54>
add    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.editor = type { i32 }
define i32 @prev_line(%struct.editor* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.editor*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store %struct.editor* %0, %struct.editor** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %40
11: ; preds = %2
br label %12
12: ; preds = %23, %11
%13 = load i32, i32* %5
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = load %struct.editor*, %struct.editor** %4
%17 = load i32, i32* %5
%18 = add nsw i32 %17, -1
store i32 %18, i32* %5
%19 = call i32 @get(%struct.editor* %16, i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, 10
br i1 %21, label %22, label %23
22: ; preds = %15
br label %24
23: ; preds = %15
br label %12
24: ; preds = %22, %12
br label %25
25: ; preds = %38, %24
%26 = load i32, i32* %5
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %25
%29 = load %struct.editor*, %struct.editor** %4
%30 = load i32, i32* %5
%31 = add nsw i32 %30, -1
store i32 %31, i32* %5
%32 = call i32 @get(%struct.editor* %29, i32 %31)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %38
35: ; preds = %28
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
br label %40
38: ; preds = %28
br label %25
39: ; preds = %25
store i32 0, i32* %3
br label %40
40: ; preds = %39, %35, %10
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
%struct.editor = type { i32 }
define i32 @prev_line(%struct.editor* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %20, label %4
4: ; preds = %2, %7
%5 = phi i32 [ %8, %7 ], [ %1, %2 ]
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = add nsw i32 %5, -1
%9 = tail call i32 @get(%struct.editor* %0, i32 %8)
%10 = icmp eq i32 %9, 10
br i1 %10, label %11, label %4
11: ; preds = %7, %4
%12 = phi i32 [ %5, %4 ], [ %8, %7 ]
br label %13
13: ; preds = %11, %16
%14 = phi i32 [ %17, %16 ], [ %12, %11 ]
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = add nsw i32 %14, -1
%18 = tail call i32 @get(%struct.editor* %0, i32 %17)
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %13
20: ; preds = %16, %13, %2
%21 = phi i32 [ -1, %2 ], [ 0, %13 ], [ %14, %16 ]
ret i32 %21
}