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

/* Variables and functions */
int /*<<< orphan*/ assert_failed(char *, int);
int buf_read_u8(struct buffer *);
int /*<<< orphan*/ strlen(char *);
int buf_parse(struct buffer *buf, const int delim, char *line, const int size) {
  int eol = 0;
  int n = 0;
  int c;
  do {
    if (!(size > 0))
      assert_failed("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/Bytewerk/uClinux-ipcam/"
                    "refs/heads/master/buffer.c",
                    650);
  } while (0);
  do {
    c = buf_read_u8(buf);
    if (c < 0)
      eol = 1;
    if (c <= 0 || c == delim)
      c = 0;
    if (n >= size)
      break;
    line[n++] = c;
  } while (c);
  line[size - 1] = '\0';
  return !(eol && !strlen(line));
}


x86 assembly (clang, -O0):
<buf_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     116f <buf_parse+0x3f>
lea    0xe9b(%rip),%rdi
mov    $0x28a,%esi
call   1050 <assert_failed@plt>
jmp    1174 <buf_parse+0x44>
jmp    1179 <buf_parse+0x49>
mov    -0x8(%rbp),%rdi
call   1040 <buf_read_u8@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1196 <buf_parse+0x66>
movl   $0x1,-0x20(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    11ac <buf_parse+0x7c>
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11b3 <buf_parse+0x83>
movl   $0x0,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     11c4 <buf_parse+0x94>
jmp    11e8 <buf_parse+0xb8>
mov    -0x28(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
cmpl   $0x0,-0x28(%rbp)
jne    1179 <buf_parse+0x49>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
xor    %eax,%eax
cmpl   $0x0,-0x20(%rbp)
mov    %al,-0x29(%rbp)
je     121c <buf_parse+0xec>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buf_parse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r12
mov    %esi,0x4(%rsp)
mov    %rdi,%r13
test   %ecx,%ecx
jg     115d <buf_parse+0x2d>
lea    0xead(%rip),%rdi
mov    $0x28a,%esi
call   1050 <assert_failed@plt>
xor    %ebp,%ebp
test   %r14d,%r14d
mov    $0x0,%ebx
mov    %r14d,(%rsp)
cmovg  %r14d,%ebx
xor    %r15d,%r15d
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
call   1040 <buf_read_u8@plt>
mov    %r12,%rdi
cmp    0x4(%rsp),%eax
mov    %eax,%ecx
cmove  %ebp,%ecx
test   %eax,%eax
mov    $0x1,%eax
cmovs  %eax,%r14d
cmovle %ebp,%ecx
cmp    %r15,%rbx
je     11b3 <buf_parse+0x83>
mov    %cl,(%rdi,%r15,1)
add    $0x1,%r15
test   %ecx,%ecx
jne    1180 <buf_parse+0x50>
movslq (%rsp),%rax
movb   $0x0,-0x1(%rax,%rdi,1)
test   %r14d,%r14d
je     11d1 <buf_parse+0xa1>
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
setne  %al
jmp    11d6 <buf_parse+0xa6>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.buffer = type { i32 }
@.str = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Bytewerk/uClinux-ipcam/refs/heads/master/buffer.c\00"
define i32 @buf_parse(%struct.buffer* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca %struct.buffer*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store %struct.buffer* %0, %struct.buffer** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %12
12: ; preds = %4
%13 = load i32, i32* %8
%14 = icmp sgt i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = call i32 @assert_failed(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i32 650)
br label %17
17: ; preds = %15, %12
br label %18
18: ; preds = %17
br label %19
19: ; preds = %46, %18
%20 = load %struct.buffer*, %struct.buffer** %5
%21 = call i32 @buf_read_u8(%struct.buffer* %20)
store i32 %21, i32* %11
%22 = load i32, i32* %11
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 1, i32* %9
br label %25
25: ; preds = %24, %19
%26 = load i32, i32* %11
%27 = icmp sle i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = load i32, i32* %11
%30 = load i32, i32* %6
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %28, %25
store i32 0, i32* %11
br label %33
33: ; preds = %32, %28
%34 = load i32, i32* %10
%35 = load i32, i32* %8
%36 = icmp sge i32 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %33
br label %49
38: ; preds = %33
%39 = load i32, i32* %11
%40 = trunc i32 %39 to i8
%41 = load i8*, i8** %7
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
%44 = sext i32 %42 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
store i8 %40, i8* %45
br label %46
46: ; preds = %38
%47 = load i32, i32* %11
%48 = icmp ne i32 %47, 0
br i1 %48, label %19, label %49
49: ; preds = %46, %37
%50 = load i8*, i8** %7
%51 = load i32, i32* %8
%52 = sub nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %50, i64 %53
store i8 0, i8* %54
%55 = load i32, i32* %9
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %49
%58 = load i8*, i8** %7
%59 = call i32 @strlen(i8* %58)
%60 = icmp ne i32 %59, 0
%61 = xor i1 %60, true
br label %62
62: ; preds = %57, %49
%63 = phi i1 [ false, %49 ], [ %61, %57 ]
%64 = xor i1 %63, true
%65 = zext i1 %64 to i32
ret i32 %65
}

LLVM IR (-O2):
%struct.buffer = type { i32 }
@.str = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Bytewerk/uClinux-ipcam/refs/heads/master/buffer.c\00"
define i32 @buf_parse(%struct.buffer* %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = tail call i32 @assert_failed(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i32 650)
br label %8
8: ; preds = %6, %4
%9 = call i32 @llvm.smax.i32(i32 %3, i32 0)
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %22, %8
%12 = phi i64 [ %24, %22 ], [ 0, %8 ]
%13 = phi i32 [ %16, %22 ], [ 0, %8 ]
%14 = tail call i32 @buf_read_u8(%struct.buffer* %0)
%15 = icmp slt i32 %14, 0
%16 = select i1 %15, i32 1, i32 %13
%17 = icmp slt i32 %14, 1
%18 = icmp eq i32 %14, %1
%19 = or i1 %17, %18
%20 = select i1 %19, i32 0, i32 %14
%21 = icmp eq i64 %12, %10
br i1 %21, label %27, label %22
22: ; preds = %11
%23 = trunc i32 %20 to i8
%24 = add nuw nsw i64 %12, 1
%25 = getelementptr inbounds i8, i8* %2, i64 %12
store i8 %23, i8* %25
%26 = icmp eq i32 %20, 0
br i1 %26, label %27, label %11
27: ; preds = %11, %22
%28 = add nsw i32 %3, -1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %2, i64 %29
store i8 0, i8* %30
%31 = icmp eq i32 %16, 0
br i1 %31, label %36, label %32
32: ; preds = %27
%33 = tail call i32 @strlen(i8* %2)
%34 = icmp ne i32 %33, 0
%35 = zext i1 %34 to i32
br label %36
36: ; preds = %32, %27
%37 = phi i32 [ 1, %27 ], [ %35, %32 ]
ret i32 %37
}