#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ stdout;
uint32_t get_int(char *buff, size_t len) {
  if (len != 2 && len != 4) {
    fprintf(stdout, "Bad data length!\n");
    return 0xffffffff;
  }
  uint32_t data = 0;
  uint8_t *i8 = (uint8_t *)&data;
  if (len == 2)
    memcpy(i8, buff, 2);
  else
    memcpy(i8, buff, 4);
  return data;
}


x86 assembly (clang, -O0):
<get_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x2,-0x18(%rbp)
je     1167 <get_int+0x47>
cmpq   $0x4,-0x18(%rbp)
je     1167 <get_int+0x47>
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
lea    0xeaa(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b0 <get_int+0x90>
movl   $0x0,-0x1c(%rbp)
lea    -0x1c(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x2,-0x18(%rbp)
jne    1198 <get_int+0x78>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
jmp    11aa <get_int+0x8a>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_int>:
push   %rax
mov    %rdi,%rax
cmp    $0x2,%rsi
je     1130 <get_int+0x10>
cmp    $0x4,%rsi
jne    115a <get_int+0x3a>
movl   $0x0,0x4(%rsp)
xor    %ecx,%ecx
cmp    $0x2,%rsi
setne  %cl
lea    (%rcx,%rcx,1),%edx
add    $0x2,%edx
lea    0x4(%rsp),%rdi
mov    %rax,%rsi
call   1040 <memcpy@plt>
mov    0x4(%rsp),%eax
pop    %rcx
ret
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [18 x i8] c"Bad data length!\0A\00"
define i32 @get_int(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %4
store i64 %1, i64* %5
%8 = load i64, i64* %5
%9 = icmp ne i64 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i64, i64* %5
%12 = icmp ne i64 %11, 4
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @stdout
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %29
16: ; preds = %10, %2
store i32 0, i32* %6
store i32* %6, i32** %7
%17 = load i64, i64* %5
%18 = icmp eq i64 %17, 2
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32*, i32** %7
%21 = load i8*, i8** %4
%22 = call i32 @memcpy(i32* %20, i8* %21, i32 2)
br label %27
23: ; preds = %16
%24 = load i32*, i32** %7
%25 = load i8*, i8** %4
%26 = call i32 @memcpy(i32* %24, i8* %25, i32 4)
br label %27
27: ; preds = %23, %19
%28 = load i32, i32* %6
store i32 %28, i32* %3
br label %29
29: ; preds = %27, %13
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [18 x i8] c"Bad data length!\0A\00"
define i32 @get_int(i8* %0, i64 %1) {
%3 = alloca i32
switch i64 %1, label %4 [
i64 4, label %7
i64 2, label %7
]
4: ; preds = %2
%5 = load i32, i32* @stdout
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %13
7: ; preds = %2, %2
%8 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%9 = icmp eq i64 %1, 2
%10 = select i1 %9, i32 2, i32 4
%11 = call i32 @memcpy(i32* %3, i8* %0, i32 %10)
%12 = load i32, i32* %3
br label %13
13: ; preds = %7, %4
%14 = phi i32 [ -1, %4 ], [ %12, %7 ]
ret i32 %14
}