#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int getHeaderSize(char *msg) {
  if (msg == NULL) {
    fprintf(stderr, "ERR: NULL msg received\n");
    return -1;
  }
  int size = 0;
  while (*(msg + sizeof(char) * size) != '\n') {
    if (*(msg + sizeof(char) * size) == '\0') {
      fprintf(stderr, "ERR: Expected \\n before end of string\n");
      return -1;
    }
    size++;
  }
  return size;
}


x86 assembly (clang, -O0):
<getHeaderSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1148 <getHeaderSize+0x38>
mov    0x2eb2(%rip),%rax
mov    (%rax),%edi
lea    0xec9(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <getHeaderSize+0xa6>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x0,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     11b0 <getHeaderSize+0xa0>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x0,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    11a2 <getHeaderSize+0x92>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <getHeaderSize+0xa6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114f <getHeaderSize+0x3f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getHeaderSize>:
push   %rax
test   %rdi,%rdi
je     1133 <getHeaderSize+0x23>
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
movzbl (%rdi,%rax,1),%ecx
cmp    $0xa,%cl
je     115f <getHeaderSize+0x4f>
test   %cl,%cl
je     1145 <getHeaderSize+0x35>
add    $0x1,%rax
jmp    1120 <getHeaderSize+0x10>
mov    0x2ea6(%rip),%rax
mov    (%rax),%edi
lea    0xebd(%rip),%rsi
jmp    1155 <getHeaderSize+0x45>
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
lea    0xec3(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"ERR: NULL msg received\0A\00"
@.str.1 = [39 x i8] c"ERR: Expected \\n before end of string\0A\00"
define i32 @getHeaderSize(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %37
10: ; preds = %1
store i32 0, i32* %4
br label %11
11: ; preds = %32, %10
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = mul i64 1, %14
%16 = getelementptr inbounds i8, i8* %12, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 10
br i1 %19, label %20, label %35
20: ; preds = %11
%21 = load i8*, i8** %3
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = mul i64 1, %23
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %37
32: ; preds = %20
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %11
35: ; preds = %11
%36 = load i32, i32* %4
store i32 %36, i32* %2
br label %37
37: ; preds = %35, %29, %7
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"ERR: NULL msg received\0A\00"
@.str.1 = [39 x i8] c"ERR: Expected \\n before end of string\0A\00"
define i32 @getHeaderSize(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %17
6: ; preds = %1, %13
%7 = phi i64 [ %14, %13 ], [ 0, %1 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
switch i8 %9, label %13 [
i8 10, label %15
i8 0, label %10
]
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %17
13: ; preds = %6
%14 = add nuw i64 %7, 1
br label %6
15: ; preds = %6
%16 = trunc i64 %7 to i32
br label %17
17: ; preds = %15, %10, %3
%18 = phi i32 [ -1, %3 ], [ -1, %10 ], [ %16, %15 ]
ret i32 %18
}