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

/* Variables and functions */
int gh_http_readline(int, char *, int);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, char *);
int http_parse_header(int socket) {
  int lines = 0, ret = 0;
  char header_line[1024];
  while ((ret = gh_http_readline(socket, header_line, 1024)))
    printf("line %d => %s\n", lines++, header_line);
  return ret;
}


x86 assembly (clang, -O0):
<http_parse_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1030 <gh_http_readline@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     117f <http_parse_header+0x5f>
mov    -0x8(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
lea    -0x410(%rbp),%rdx
lea    0xe8b(%rip),%rdi
call   1040 <printf@plt>
jmp    113c <http_parse_header+0x1c>
mov    -0xc(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_parse_header>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %edi,%r15d
mov    %rsp,%rsi
mov    $0x400,%edx
call   1030 <gh_http_readline@plt>
test   %eax,%eax
je     1174 <http_parse_header+0x54>
xor    %esi,%esi
lea    0xeb6(%rip),%r14
mov    %rsp,%rbx
nopl   (%rax)
lea    0x1(%rsi),%ebp
mov    %r14,%rdi
mov    %rbx,%rdx
call   1040 <printf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1030 <gh_http_readline@plt>
mov    %ebp,%esi
test   %eax,%eax
jne    1150 <http_parse_header+0x30>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"line %d => %s\0A\00"
define i32 @http_parse_header(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %11, %1
%7 = load i32, i32* %2
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = call i32 @gh_http_readline(i32 %7, i8* %8, i32 1024)
store i32 %9, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %6
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
store i32 %13, i32* %3
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %14)
br label %6
16: ; preds = %6
%17 = load i32, i32* %4
ret i32 %17
}

LLVM IR (-O2):
@.str = [15 x i8] c"line %d => %s\0A\00"
define i32 @http_parse_header(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @gh_http_readline(i32 %0, i8* %3, i32 1024)
%5 = icmp eq i32 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %1, %6
%7 = phi i32 [ %8, %6 ], [ 0, %1 ]
%8 = add nuw nsw i32 %7, 1
%9 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %7, i8* %3)
%10 = call i32 @gh_http_readline(i32 %0, i8* %3, i32 1024)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %6
12: ; preds = %6, %1
ret i32 0
}