#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*/ package_get_log_size(char *);
int /*<<< orphan*/ printf(char *, ...);
int write_buffer(int, char *, char *);
unsigned int get_log_size(int tty) {
  char buffer[17];
  int res;
  printf("++ read log size:\n");
  package_get_log_size(buffer);
  res = write_buffer(tty, buffer, buffer);
  if (res < 17) {
    printf("?? Can't get log size, package is too short\n");
    return res;
  }
  unsigned int days_in_log =
      (((unsigned char)buffer[0x02] << 24) +
       ((unsigned char)buffer[0x03] << 16) +
       ((unsigned char)buffer[0x04] << 8) + (unsigned char)buffer[0x05]);
  printf("-- days in log will be: %08x\n", days_in_log);
  return days_in_log;
}


x86 assembly (clang, -O0):
<get_log_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1050 <package_get_log_size@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1030 <write_buffer@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x11,-0x24(%rbp)
jge    1188 <get_log_size+0x58>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c1 <get_log_size+0x91>
movzbl -0x1e(%rbp),%eax
shl    $0x18,%eax
movzbl -0x1d(%rbp),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
movzbl -0x1c(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
movzbl -0x1b(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_log_size>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
lea    0xecf(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <package_get_log_size@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rbx,%rdx
call   1040 <write_buffer@plt>
cmp    $0x10,%eax
jg     1181 <get_log_size+0x41>
mov    %eax,%ebx
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
jmp    1197 <get_log_size+0x57>
mov    0x2(%rsp),%ebx
bswap  %ebx
lea    0xe72(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"++ read log size:\0A\00"
@.str.1 = [45 x i8] c"?? Can't get log size, package is too short\0A\00"
@.str.2 = [30 x i8] c"-- days in log will be: %08x\0A\00"
define i32 @get_log_size(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [17 x i8]
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%9 = call i32 @package_get_log_size(i8* %8)
%10 = load i32, i32* %3
%11 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%13 = call i32 @write_buffer(i32 %10, i8* %11, i8* %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 17
br i1 %15, label %16, label %19
16: ; preds = %1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* %5
store i32 %18, i32* %2
br label %41
19: ; preds = %1
%20 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 2
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = shl i32 %22, 24
%24 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 3
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = shl i32 %26, 16
%28 = add nsw i32 %23, %27
%29 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 4
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = shl i32 %31, 8
%33 = add nsw i32 %28, %32
%34 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 5
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = add nsw i32 %33, %36
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %6
store i32 %40, i32* %2
br label %41
41: ; preds = %19, %16
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@.str.2 = [30 x i8] c"-- days in log will be: %08x\0A\00"
@str = [18 x i8] c"++ read log size:\00"
@str.3 = [44 x i8] c"?? Can't get log size, package is too short\00"
define i32 @get_log_size(i32 %0) {
%2 = alloca [17 x i8]
%3 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%5 = call i32 @package_get_log_size(i8* %3)
%6 = call i32 @write_buffer(i32 %0, i8* %3, i8* %3)
%7 = icmp slt i32 %6, 17
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.3, i64 0, i64 0))
br label %30
10: ; preds = %1
%11 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 2
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = shl nuw i32 %13, 24
%15 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 3
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = shl nuw nsw i32 %17, 16
%19 = or i32 %18, %14
%20 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 4
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = shl nuw nsw i32 %22, 8
%24 = or i32 %19, %23
%25 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 5
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = or i32 %24, %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %10, %8
%31 = phi i32 [ %6, %8 ], [ %28, %10 ]
ret i32 %31
}