#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 atoi(char *);
int read(int, char *, int);
scalar_t__ strcmp(char *, char *);
void get_header(int sock, int *isvalid, int *size) {
  int err = 0;
  char checksum[2] = {0};
  char msg[10] = {0};
  read(sock, checksum, 2);
  if (strcmp(checksum, "$;") == 0) {
    *isvalid = 1;
  }
  err = read(sock, msg, 10);
  msg[err] = '\0';
  *size = atoi(msg);
}


x86 assembly (clang, -O0):
<get_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x1e(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1030 <memset@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1030 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x1e(%rbp),%rsi
mov    $0x2,%edx
call   1040 <read@plt>
lea    -0x1e(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11af <get_header+0x6f>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x28(%rbp,%rax,1)
lea    -0x28(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_header>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%ebp
movw   $0x0,0x6(%rsp)
movw   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x6(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <read@plt>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1186 <get_header+0x56>
movl   $0x1,(%r14)
lea    0x8(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1030 <read@plt>
cltq
movb   $0x0,0x8(%rsp,%rax,1)
mov    %rbx,%rdi
call   1050 <atoi@plt>
mov    %eax,(%r15)
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"$;\00"
define void @get_header(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [2 x i8]
%9 = alloca [10 x i8]
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32 0, i32* %7
%10 = bitcast [2 x i8]* %8 to i8*
%11 = bitcast [10 x i8]* %9 to i8*
%12 = load i32, i32* %4
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%14 = call i32 @read(i32 %12, i8* %13, i32 2)
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = load i32*, i32** %5
store i32 1, i32* %19
br label %20
20: ; preds = %18, %3
%21 = load i32, i32* %4
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%23 = call i32 @read(i32 %21, i8* %22, i32 10)
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 %25
store i8 0, i8* %26
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%28 = call i32 @atoi(i8* %27)
%29 = load i32*, i32** %6
store i32 %28, i32* %29
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"$;\00"
define void @get_header(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i16
%5 = alloca [10 x i8]
%6 = bitcast i16* %4 to i8*
store i16 0, i16* %4
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%8 = call i32 @read(i32 %0, i8* %6, i32 2)
%9 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 1, i32* %1
br label %12
12: ; preds = %11, %3
%13 = call i32 @read(i32 %0, i8* %7, i32 10)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 %14
store i8 0, i8* %15
%16 = call i32 @atoi(i8* %7)
store i32 %16, i32* %2
ret void
}