#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 */
int EOF;
int fgetc(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
size_t strlen(char *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int setx_read_buffer(FILE *in, void (*p)(char *, size_t)) {
  char line[1024];
  size_t n;
  int c, z, stx_found = 0;
  while ((c = fgetc(in)) != EOF) {
    switch (c) {
    case 0x02:
      stx_found = 1;
      continue;
    case 0x0A:
      if ((z = fgetc(in)) == 0x03)
        return 1;
      ungetc(z, in);
      break;
    case 0x03:
      return 1;
    }
    ungetc(c, in);
    if (stx_found) {
      if (fgets(line, 1024, in)) {
        p(line, strlen(line));
        continue;
      }
    }
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<setx_read_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x434(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x42c(%rbp)
mov    0x2e75(%rip),%rcx
cmp    (%rcx),%eax
je     1292 <setx_read_buffer+0x152>
mov    -0x42c(%rbp),%eax
mov    %eax,-0x438(%rbp)
sub    $0x2,%eax
je     11bd <setx_read_buffer+0x7d>
jmp    1195 <setx_read_buffer+0x55>
mov    -0x438(%rbp),%eax
sub    $0x3,%eax
je     1204 <setx_read_buffer+0xc4>
jmp    11a9 <setx_read_buffer+0x69>
mov    -0x438(%rbp),%eax
sub    $0xa,%eax
je     11cc <setx_read_buffer+0x8c>
jmp    1210 <setx_read_buffer+0xd0>
movl   $0x1,-0x434(%rbp)
jmp    115d <setx_read_buffer+0x1d>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x430(%rbp)
cmp    $0x3,%eax
jne    11f0 <setx_read_buffer+0xb0>
movl   $0x1,-0x4(%rbp)
jmp    1299 <setx_read_buffer+0x159>
mov    -0x430(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <ungetc@plt>
jmp    1210 <setx_read_buffer+0xd0>
movl   $0x1,-0x4(%rbp)
jmp    1299 <setx_read_buffer+0x159>
mov    -0x42c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <ungetc@plt>
cmpl   $0x0,-0x434(%rbp)
je     128d <setx_read_buffer+0x14d>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1288 <setx_read_buffer+0x148>
mov    -0x18(%rbp),%rax
mov    %rax,-0x440(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x448(%rbp)
lea    -0x420(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x448(%rbp),%rdi
mov    %rax,%rsi
mov    -0x440(%rbp),%rax
call   *%rax
jmp    115d <setx_read_buffer+0x1d>
jmp    128d <setx_read_buffer+0x14d>
jmp    1292 <setx_read_buffer+0x152>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setx_read_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
call   1040 <fgetc@plt>
mov    %eax,%ebp
mov    0x2e83(%rip),%rax
cmp    (%rax),%ebp
jne    117f <setx_read_buffer+0x3f>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r13b
mov    %rsp,%r15
jmp    11ad <setx_read_buffer+0x6d>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
xor    %r13d,%r13d
mov    $0x0,%ebx
mov    0x2e3f(%rip),%rax
cmp    (%rax),%ebp
je     116b <setx_read_buffer+0x2b>
cmp    $0x2,%ebp
je     1190 <setx_read_buffer+0x50>
mov    $0x1,%ebx
cmp    $0xa,%ebp
je     11d0 <setx_read_buffer+0x90>
cmp    $0x3,%ebp
jne    11e7 <setx_read_buffer+0xa7>
jmp    116b <setx_read_buffer+0x2b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
call   1040 <fgetc@plt>
cmp    $0x3,%eax
je     116b <setx_read_buffer+0x2b>
mov    %eax,%edi
mov    %r12,%rsi
call   1060 <ungetc@plt>
mov    %ebp,%edi
mov    %r12,%rsi
call   1060 <ungetc@plt>
test   $0x1,%r13b
jne    1169 <setx_read_buffer+0x29>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1169 <setx_read_buffer+0x29>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   *%r14
jmp    1190 <setx_read_buffer+0x50>

LLVM IR (-O0):
@EOF = global i32 0
define i32 @setx_read_buffer(i32* %0, void (i8*, i64)* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca void (i8*, i64)*
%6 = alloca [1024 x i8]
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %4
store void (i8*, i64)* %1, void (i8*, i64)** %5
store i32 0, i32* %10
br label %11
11: ; preds = %40, %18, %2
%12 = load i32*, i32** %4
%13 = call i32 @fgetc(i32* %12)
store i32 %13, i32* %8
%14 = load i32, i32* @EOF
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %47
16: ; preds = %11
%17 = load i32, i32* %8
switch i32 %17, label %29 [
i32 2, label %18
i32 10, label %19
i32 3, label %28
]
18: ; preds = %16
store i32 1, i32* %10
br label %11
19: ; preds = %16
%20 = load i32*, i32** %4
%21 = call i32 @fgetc(i32* %20)
store i32 %21, i32* %9
%22 = icmp eq i32 %21, 3
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 1, i32* %3
br label %48
24: ; preds = %19
%25 = load i32, i32* %9
%26 = load i32*, i32** %4
%27 = call i32 @ungetc(i32 %25, i32* %26)
br label %29
28: ; preds = %16
store i32 1, i32* %3
br label %48
29: ; preds = %16, %24
%30 = load i32, i32* %8
%31 = load i32*, i32** %4
%32 = call i32 @ungetc(i32 %30, i32* %31)
%33 = load i32, i32* %10
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %46
35: ; preds = %29
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%37 = load i32*, i32** %4
%38 = call i64 @fgets(i8* %36, i32 1024, i32* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %35
%41 = load void (i8*, i64)*, void (i8*, i64)** %5
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%44 = call i64 @strlen(i8* %43)
br label %11
45: ; preds = %35
br label %46
46: ; preds = %45, %29
br label %47
47: ; preds = %46, %11
store i32 0, i32* %3
br label %48
48: ; preds = %47, %28, %23
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @setx_read_buffer(i32* nocapture %0, void (i8*, i64)* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @fgetc(i32* %0)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %27, label %8
8: ; preds = %2, %23
%9 = phi i32 [ %24, %23 ], [ %5, %2 ]
%10 = phi i1 [ false, %23 ], [ true, %2 ]
switch i32 %9, label %16 [
i32 2, label %23
i32 10, label %11
i32 3, label %27
]
11: ; preds = %8
%12 = call i32 @fgetc(i32* %0)
%13 = icmp eq i32 %12, 3
br i1 %13, label %27, label %14
14: ; preds = %11
%15 = call i32 @ungetc(i32 %12, i32* %0)
br label %16
16: ; preds = %8, %14
%17 = call i32 @ungetc(i32 %9, i32* %0)
br i1 %10, label %27, label %18
18: ; preds = %16
%19 = call i64 @fgets(i8* %4, i32 1024, i32* %0)
%20 = icmp eq i64 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %18
%22 = call i64 @strlen(i8* %4)
br label %23
23: ; preds = %21, %8
%24 = call i32 @fgetc(i32* %0)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %8
27: ; preds = %11, %8, %16, %18, %23, %2
%28 = phi i32 [ 0, %2 ], [ 0, %23 ], [ 0, %18 ], [ 0, %16 ], [ 1, %8 ], [ 1, %11 ]
ret i32 %28
}