#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*/ FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ SEEK_CUR;
char fcpeek(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int get_column(FILE *i) {
  int cur_pos = ftell(i);
  int offset = 0;
  char c = fcpeek(i);
  while (c != '\n' && (ftell(i) > 0) && c != EOF) {
    fseek(i, -1, SEEK_CUR);
    offset++;
    c = fcpeek(i);
  }
  fseek(i, cur_pos, SEEK_CUR);
  return offset;
}


x86 assembly (clang, -O0):
<get_column>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ftell@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fcpeek@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x12(%rbp)
je     119c <get_column+0x6c>
mov    -0x8(%rbp),%rdi
call   1030 <ftell@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x12(%rbp)
jle    119c <get_column+0x6c>
movsbl -0x11(%rbp),%eax
mov    0x2e4f(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    11ac <get_column+0x7c>
jmp    11dd <get_column+0xad>
mov    -0x8(%rbp),%rdi
mov    0x2e31(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1040 <fseek@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fcpeek@plt>
mov    %al,-0x11(%rbp)
jmp    115b <get_column+0x2b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_column>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <ftell@plt>
mov    %eax,%r14d
mov    %r15,%rdi
call   1050 <fcpeek@plt>
xor    %ebp,%ebp
cmp    $0xa,%al
je     11a4 <get_column+0x74>
mov    %eax,%ebx
xor    %ebp,%ebp
mov    0x2e81(%rip),%r12
mov    0x2e82(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <ftell@plt>
test   %eax,%eax
jle    11a4 <get_column+0x74>
cmp    (%r12),%bl
je     11a4 <get_column+0x74>
mov    0x0(%r13),%edx
mov    %r15,%rdi
mov    $0xffffffff,%esi
call   1040 <fseek@plt>
add    $0x1,%ebp
mov    %r15,%rdi
call   1050 <fcpeek@plt>
mov    %eax,%ebx
cmp    $0xa,%al
jne    1170 <get_column+0x40>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    %r14d,%esi
call   1040 <fseek@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i8 0
@SEEK_CUR = global i32 0
define i32 @get_column(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32* %0, i32** %2
%6 = load i32*, i32** %2
%7 = call i32 @ftell(i32* %6)
store i32 %7, i32* %3
store i32 0, i32* %4
%8 = load i32*, i32** %2
%9 = call signext i8 @fcpeek(i32* %8)
store i8 %9, i8* %5
br label %10
10: ; preds = %26, %1
%11 = load i8, i8* %5
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 10
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = load i32*, i32** %2
%16 = call i32 @ftell(i32* %15)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i8, i8* %5
%20 = sext i8 %19 to i32
%21 = load i8, i8* @EOF
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br label %24
24: ; preds = %18, %14, %10
%25 = phi i1 [ false, %14 ], [ false, %10 ], [ %23, %18 ]
br i1 %25, label %26, label %34
26: ; preds = %24
%27 = load i32*, i32** %2
%28 = load i32, i32* @SEEK_CUR
%29 = call i32 @fseek(i32* %27, i32 -1, i32 %28)
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
%32 = load i32*, i32** %2
%33 = call signext i8 @fcpeek(i32* %32)
store i8 %33, i8* %5
br label %10
34: ; preds = %24
%35 = load i32*, i32** %2
%36 = load i32, i32* %3
%37 = load i32, i32* @SEEK_CUR
%38 = call i32 @fseek(i32* %35, i32 %36, i32 %37)
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@EOF = global i8 0
@SEEK_CUR = global i32 0
define i32 @get_column(i32* %0) {
%2 = tail call i32 @ftell(i32* %0)
%3 = tail call signext i8 @fcpeek(i32* %0)
%4 = icmp eq i8 %3, 10
br i1 %4, label %19, label %5
5: ; preds = %1, %13
%6 = phi i8 [ %17, %13 ], [ %3, %1 ]
%7 = phi i32 [ %16, %13 ], [ 0, %1 ]
%8 = tail call i32 @ftell(i32* %0)
%9 = icmp slt i32 %8, 1
%10 = load i8, i8* @EOF
%11 = icmp eq i8 %6, %10
%12 = select i1 %9, i1 true, i1 %11
br i1 %12, label %19, label %13
13: ; preds = %5
%14 = load i32, i32* @SEEK_CUR
%15 = tail call i32 @fseek(i32* %0, i32 -1, i32 %14)
%16 = add nuw nsw i32 %7, 1
%17 = tail call signext i8 @fcpeek(i32* %0)
%18 = icmp eq i8 %17, 10
br i1 %18, label %19, label %5
19: ; preds = %5, %13, %1
%20 = phi i32 [ 0, %1 ], [ %16, %13 ], [ %7, %5 ]
%21 = load i32, i32* @SEEK_CUR
%22 = tail call i32 @fseek(i32* %0, i32 %2, i32 %21)
ret i32 %20
}