#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*/ printf(char *);
int sign(char *, int /*<<< orphan*/, unsigned int *, int);
int /*<<< orphan*/ strlen(char *);
int test_short_input() {
  unsigned int result[16];
  char *short_data = "123";
  char *exact_data = "1234";
  int res;
  printf("\n* Testing signing of short data:\n");
  res = sign(short_data, strlen(short_data), result, 16);
  if (res != -1) {
    printf("\n sign() didn't report that input was too short.\n");
    return -1;
  }
  res = sign(exact_data, strlen(exact_data), result, 16);
  if (res != 0) {
    printf("\n sign() reported incorrectly that input was too short.\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_short_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    0xebe(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xeb7(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
mov    -0x58(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x58(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%esi
lea    -0x50(%rbp),%rdx
mov    $0x10,%ecx
call   1050 <sign@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
je     11a7 <test_short_input+0x77>
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f8 <test_short_input+0xc8>
mov    -0x60(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x60(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x78(%rbp),%rdi
mov    %eax,%esi
lea    -0x50(%rbp),%rdx
mov    $0x10,%ecx
call   1050 <sign@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
je     11f1 <test_short_input+0xc1>
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f8 <test_short_input+0xc8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_short_input>:
push   %rbx
sub    $0x40,%rsp
lea    0xecd(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb8(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x10,%ecx
call   1050 <sign@plt>
cmp    $0xffffffff,%eax
je     1170 <test_short_input+0x40>
lea    0xef5(%rip),%rdi
jmp    119c <test_short_input+0x6c>
lea    0xe8d(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x10,%ecx
call   1050 <sign@plt>
test   %eax,%eax
je     11ac <test_short_input+0x7c>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x40,%rsp
pop    %rbx
ret
xor    %eax,%eax
jmp    11a6 <test_short_input+0x76>

LLVM IR (-O0):
@.str = [4 x i8] c"123\00"
@.str.1 = [5 x i8] c"1234\00"
@.str.2 = [35 x i8] c"\0A* Testing signing of short data:\0A\00"
@.str.3 = [50 x i8] c"\0A sign() didn't report that input was too short.\0A\00"
@.str.4 = [57 x i8] c"\0A sign() reported incorrectly that input was too short.\0A\00"
define i32 @test_short_input() {
%1 = alloca i32
%2 = alloca [16 x i32]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %4
%6 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%7 = load i8*, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%11 = call i32 @sign(i8* %7, i32 %9, i32* %10, i32 16)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %27
16: ; preds = %0
%17 = load i8*, i8** %4
%18 = load i8*, i8** %4
%19 = call i32 @strlen(i8* %18)
%20 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%21 = call i32 @sign(i8* %17, i32 %19, i32* %20, i32 16)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %16
%25 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %27
26: ; preds = %16
store i32 0, i32* %1
br label %27
27: ; preds = %26, %24, %14
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [4 x i8] c"123\00"
@.str.1 = [5 x i8] c"1234\00"
@str = [34 x i8] c"\0A* Testing signing of short data:\00"
@str.5 = [56 x i8] c"\0A sign() reported incorrectly that input was too short.\00"
@str.6 = [49 x i8] c"\0A sign() didn't report that input was too short.\00"
define i32 @test_short_input() {
%1 = alloca [16 x i32]
%2 = bitcast [16 x i32]* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 0
%6 = call i32 @sign(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %4, i32* %5, i32 16)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @sign(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32* %5, i32 16)
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %8, %0
%13 = phi i8* [ getelementptr inbounds ([49 x i8], [49 x i8]* @str.6, i64 0, i64 0), %0 ], [ getelementptr inbounds ([56 x i8], [56 x i8]* @str.5, i64 0, i64 0), %8 ]
%14 = call i32 @puts(i8* dereferenceable(1) %13)
br label %15
15: ; preds = %12, %8
%16 = phi i32 [ 0, %8 ], [ -1, %12 ]
ret i32 %16
}