#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 /*<<< orphan*/ free(char *);
char *get_response(int *);
scalar_t__ write(int, char *, int);
int write_headers(int fd) {
  int headers_len;
  char *headers = get_response(&headers_len);
  int error =
      (!headers || headers_len <= 0 || write(fd, headers, headers_len) < 0);
  free(headers);
  return error;
}


x86 assembly (clang, -O0):
<write_headers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <get_response@plt>
mov    %rax,-0x10(%rbp)
mov    $0x1,%al
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x15(%rbp)
je     1180 <write_headers+0x50>
mov    $0x1,%al
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x15(%rbp)
jle    1180 <write_headers+0x50>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1040 <write@plt>
cmp    $0x0,%rax
setl   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_headers>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
lea    0xc(%rsp),%rdi
call   1050 <get_response@plt>
mov    %rax,%r14
mov    $0x1,%ebx
test   %rax,%rax
je     116a <write_headers+0x3a>
mov    0xc(%rsp),%edx
test   %edx,%edx
jle    116a <write_headers+0x3a>
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <write@plt>
mov    %rax,%rbx
shr    $0x3f,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @write_headers(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %2
%6 = call i8* @get_response(i32* %3)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %18
9: ; preds = %1
%10 = load i32, i32* %3
%11 = icmp sle i32 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = load i32, i32* %2
%14 = load i8*, i8** %4
%15 = load i32, i32* %3
%16 = call i64 @write(i32 %13, i8* %14, i32 %15)
%17 = icmp slt i64 %16, 0
br label %18
18: ; preds = %12, %9, %1
%19 = phi i1 [ true, %9 ], [ true, %1 ], [ %17, %12 ]
%20 = zext i1 %19 to i32
store i32 %20, i32* %5
%21 = load i8*, i8** %4
%22 = call i32 @free(i8* %21)
%23 = load i32, i32* %5
ret i32 %23
}

LLVM IR (-O2):
define i32 @write_headers(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i8* @get_response(i32* %2)
%5 = icmp eq i8* %4, null
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 1
%8 = select i1 %5, i1 true, i1 %7
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = call i64 @write(i32 %0, i8* %4, i32 %6)
%11 = lshr i64 %10, 63
%12 = trunc i64 %11 to i32
br label %13
13: ; preds = %9, %1
%14 = phi i32 [ 1, %1 ], [ %12, %9 ]
%15 = call i32 @free(i8* %4)
ret i32 %14
}