#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 /*<<< orphan*/ printf(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];
  char msg[10];
  printf("reading sock\n");
  read(sock, checksum, 2);
  if (strcmp(checksum, "#;") == 0) {
    *isvalid = 1;
    printf("is valid\n");
  } else {
    printf("is not valid\n");
  }
  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    0xe9f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x1e(%rbp),%rsi
mov    $0x2,%edx
call   1040 <read@plt>
lea    -0x1e(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11ac <get_header+0x6c>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
jmp    11b8 <get_header+0x78>
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
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,%r14
mov    %rsi,%r15
mov    %edi,%ebp
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1040 <read@plt>
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     118f <get_header+0x4f>
lea    0xe83(%rip),%rdi
jmp    119d <get_header+0x5d>
movl   $0x1,(%r15)
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
lea    0xe(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1040 <read@plt>
cltq
movb   $0x0,0xe(%rsp,%rax,1)
mov    %rbx,%rdi
call   1060 <atoi@plt>
mov    %eax,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"reading sock\0A\00"
@.str.1 = [3 x i8] c"#;\00"
@.str.2 = [10 x i8] c"is valid\0A\00"
@.str.3 = [14 x i8] c"is not valid\0A\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 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %4
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 2)
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = load i32*, i32** %5
store i32 1, i32* %18
%19 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %22
20: ; preds = %3
%21 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = load i32, i32* %4
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%25 = call i32 @read(i32 %23, i8* %24, i32 10)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 %27
store i8 0, i8* %28
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%30 = call i32 @atoi(i8* %29)
%31 = load i32*, i32** %6
store i32 %30, i32* %31
ret void
}

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