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

/* Variables and functions */
long atol(char *);
int /*<<< orphan*/ log_exit(char *, long);
char *lookup_header_field_value(struct HTTPRequest *, char *);
long content_length(struct HTTPRequest *req) {
  char *val;
  long len;
  val = lookup_header_field_value(req, "Content-Length");
  if (!val) {
    return 0;
  }
  len = atol(val);
  if (len < 0) {
    log_exit("negative Content-Length value: %d", len);
  }
  return len;
}


x86 assembly (clang, -O0):
<content_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1030 <lookup_header_field_value@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1168 <content_length+0x38>
movq   $0x0,-0x8(%rbp)
jmp    1198 <content_length+0x68>
mov    -0x18(%rbp),%rdi
call   1040 <atol@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1190 <content_length+0x60>
mov    -0x20(%rbp),%rsi
lea    0xe84(%rip),%rdi
call   1050 <log_exit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<content_length>:
push   %rbx
lea    0xec8(%rip),%rsi
call   1030 <lookup_header_field_value@plt>
test   %rax,%rax
je     1163 <content_length+0x33>
mov    %rax,%rdi
call   1040 <atol@plt>
mov    %rax,%rbx
test   %rax,%rax
jns    1165 <content_length+0x35>
lea    0xeb6(%rip),%rdi
mov    %rbx,%rsi
call   1050 <log_exit@plt>
jmp    1165 <content_length+0x35>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.HTTPRequest = type { i32 }
@.str = [15 x i8] c"Content-Length\00"
@.str.1 = [34 x i8] c"negative Content-Length value: %d\00"
define i64 @content_length(%struct.HTTPRequest* %0) {
%2 = alloca i64
%3 = alloca %struct.HTTPRequest*
%4 = alloca i8*
%5 = alloca i64
store %struct.HTTPRequest* %0, %struct.HTTPRequest** %3
%6 = load %struct.HTTPRequest*, %struct.HTTPRequest** %3
%7 = call i8* @lookup_header_field_value(%struct.HTTPRequest* %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i64 0, i64* %2
br label %21
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = call i64 @atol(i8* %12)
store i64 %13, i64* %5
%14 = load i64, i64* %5
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i64, i64* %5
%18 = call i32 @log_exit(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i64 %17)
br label %19
19: ; preds = %16, %11
%20 = load i64, i64* %5
store i64 %20, i64* %2
br label %21
21: ; preds = %19, %10
%22 = load i64, i64* %2
ret i64 %22
}

LLVM IR (-O2):
%struct.HTTPRequest = type { i32 }
@.str = [15 x i8] c"Content-Length\00"
@.str.1 = [34 x i8] c"negative Content-Length value: %d\00"
define i64 @content_length(%struct.HTTPRequest* %0) {
%2 = tail call i8* @lookup_header_field_value(%struct.HTTPRequest* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = tail call i64 @atol(i8* %2)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @log_exit(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i64 %5)
br label %9
9: ; preds = %4, %7, %1
%10 = phi i64 [ 0, %1 ], [ %5, %7 ], [ %5, %4 ]
ret i64 %10
}