#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 */
#define EOF 128
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int run_line(FILE *fp) {
  int c;
  int ret = 0;
  int linelen = 0;
  int lr = 0;
  do {
    c = fgetc(fp);
    switch (c) {
    case 'L':
    case 'l':
      lr++;
      linelen++;
      break;
    case 'R':
    case 'r':
      lr--;
      linelen++;
      break;
    case '\n':
    case EOF:
      if (c == '\n') {
        ret = 1;
      }
      if (linelen > 0) {
        printf("%s\n", lr == 0 ? "ok" : "missing");
      }
      return ret;
      break;
    }
  } while (!ret);
  return ret;
}


x86 assembly (clang, -O0):
<run_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0xa,%eax
je     11e6 <run_line+0xc6>
jmp    1161 <run_line+0x41>
mov    -0x24(%rbp),%eax
sub    $0x4c,%eax
je     11b8 <run_line+0x98>
jmp    1172 <run_line+0x52>
mov    -0x24(%rbp),%eax
sub    $0x52,%eax
je     11cf <run_line+0xaf>
jmp    1183 <run_line+0x63>
mov    -0x24(%rbp),%eax
sub    $0x6c,%eax
je     11b8 <run_line+0x98>
jmp    1194 <run_line+0x74>
mov    -0x24(%rbp),%eax
sub    $0x72,%eax
je     11cf <run_line+0xaf>
jmp    11a5 <run_line+0x85>
mov    -0x24(%rbp),%eax
sub    $0x80,%eax
je     11e6 <run_line+0xc6>
jmp    1230 <run_line+0x110>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1230 <run_line+0x110>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1230 <run_line+0x110>
cmpl   $0xa,-0x14(%rbp)
jne    11f7 <run_line+0xd7>
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1225 <run_line+0x105>
mov    -0x20(%rbp),%ecx
lea    0xdfc(%rip),%rsi
lea    0xdf2(%rip),%rax
cmp    $0x0,%ecx
cmove  %rax,%rsi
lea    0xde0(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    124c <run_line+0x12c>
jmp    1235 <run_line+0x115>
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1141 <run_line+0x21>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %r15d,%r15d
lea    0xecc(%rip),%rbp
xor    %r14d,%r14d
jmp    1150 <run_line+0x30>
add    $0xffffffff,%r14d
add    $0x1,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
lea    -0x4c(%rax),%ecx
cmp    $0x26,%ecx
ja     1180 <run_line+0x60>
movslq 0x0(%rbp,%rcx,4),%rax
add    %rbp,%rax
jmp    *%rax
add    $0x1,%r14d
add    $0x1,%r15d
jmp    1150 <run_line+0x30>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0xa,%eax
je     1195 <run_line+0x75>
cmp    $0x80,%eax
jne    1150 <run_line+0x30>
xor    %ebx,%ebx
test   %r15d,%r15d
jne    119f <run_line+0x7f>
jmp    11c0 <run_line+0xa0>
mov    $0x1,%ebx
test   %r15d,%r15d
je     11c0 <run_line+0xa0>
test   %r14d,%r14d
lea    0xef7(%rip),%rax
lea    0xef3(%rip),%rsi
cmove  %rax,%rsi
lea    0xee1(%rip),%rdi
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [3 x i8] c"ok\00"
@.str.2 = [8 x i8] c"missing\00"
define i32 @run_line(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %38, %1
%9 = load i32*, i32** %3
%10 = call i32 @fgetc(i32* %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
switch i32 %11, label %37 [
i32 76, label %12
i32 108, label %12
i32 82, label %17
i32 114, label %17
i32 10, label %22
i32 128, label %22
]
12: ; preds = %8, %8
%13 = load i32, i32* %7
%14 = add nsw i32 %13, 1
store i32 %14, i32* %7
%15 = load i32, i32* %6
%16 = add nsw i32 %15, 1
store i32 %16, i32* %6
br label %37
17: ; preds = %8, %8
%18 = load i32, i32* %7
%19 = add nsw i32 %18, -1
store i32 %19, i32* %7
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
br label %37
22: ; preds = %8, %8
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 1, i32* %5
br label %26
26: ; preds = %25, %22
%27 = load i32, i32* %6
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, 0
%32 = zext i1 %31 to i64
%33 = select i1 %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0)
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %29, %26
%36 = load i32, i32* %5
store i32 %36, i32* %2
br label %44
37: ; preds = %8, %17, %12
br label %38
38: ; preds = %37
%39 = load i32, i32* %5
%40 = icmp ne i32 %39, 0
%41 = xor i1 %40, true
br i1 %41, label %8, label %42
42: ; preds = %38
%43 = load i32, i32* %5
store i32 %43, i32* %2
br label %44
44: ; preds = %42, %35
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [3 x i8] c"ok\00"
@.str.2 = [8 x i8] c"missing\00"
define i32 @run_line(i32* nocapture %0) {
br label %2
2: ; preds = %11, %1
%3 = phi i32 [ 0, %1 ], [ %13, %11 ]
%4 = phi i32 [ 0, %1 ], [ %12, %11 ]
br label %5
5: ; preds = %2, %5
%6 = tail call i32 @fgetc(i32* %0)
switch i32 %6, label %5 [
i32 76, label %7
i32 108, label %7
i32 82, label %9
i32 114, label %9
i32 10, label %15
i32 128, label %14
]
7: ; preds = %5, %5
%8 = add nsw i32 %4, 1
br label %11
9: ; preds = %5, %5
%10 = add nsw i32 %4, -1
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ %8, %7 ], [ %10, %9 ]
%13 = add nuw nsw i32 %3, 1
br label %2
14: ; preds = %5
br label %15
15: ; preds = %5, %14
%16 = phi i32 [ 0, %14 ], [ 1, %5 ]
%17 = icmp eq i32 %3, 0
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = icmp eq i32 %4, 0
%20 = select i1 %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0)
%21 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %15, %18
ret i32 %16
}