#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*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int trim_to_p256_bytes(unsigned char dst[32], unsigned char *src, int src_len) {
  int dst_offset;
  while (*src == '\0' && src_len > 0) {
    src++;
    src_len--;
  }
  if (src_len > 32 || src_len < 1) {
    return 0;
  }
  dst_offset = 32 - src_len;
  memset(dst, 0, dst_offset);
  memcpy(dst + dst_offset, src, src_len);
  return 1;
}


x86 assembly (clang, -O0):
<trim_to_p256_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
jne    1152 <trim_to_p256_bytes+0x32>
cmpl   $0x0,-0x1c(%rbp)
setg   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1162 <trim_to_p256_bytes+0x42>
jmp    117c <trim_to_p256_bytes+0x5c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1133 <trim_to_p256_bytes+0x13>
cmpl   $0x20,-0x1c(%rbp)
jg     1190 <trim_to_p256_bytes+0x70>
cmpl   $0x1,-0x1c(%rbp)
jge    119c <trim_to_p256_bytes+0x7c>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <trim_to_p256_bytes+0xb3>
mov    $0x20,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_to_p256_bytes>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
cmpb   $0x0,(%rsi)
jne    1157 <trim_to_p256_bytes+0x37>
test   %edx,%edx
jle    1157 <trim_to_p256_bytes+0x37>
nopw   0x0(%rax,%rax,1)
cmpb   $0x0,0x1(%r15)
lea    0x1(%r15),%r15
lea    -0x1(%rdx),%ebx
jne    1159 <trim_to_p256_bytes+0x39>
cmp    $0x1,%edx
mov    %ebx,%edx
ja     1140 <trim_to_p256_bytes+0x20>
jmp    1159 <trim_to_p256_bytes+0x39>
mov    %edx,%ebx
lea    -0x21(%rbx),%ecx
xor    %eax,%eax
cmp    $0xffffffe0,%ecx
jb     118e <trim_to_p256_bytes+0x6e>
mov    $0x20,%r12d
sub    %ebx,%r12d
mov    %r14,%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1030 <memset@plt>
add    %r14,%r12
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @trim_to_p256_bytes(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
br label %9
9: ; preds = %19, %3
%10 = load i8*, i8** %6
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* %7
%16 = icmp sgt i32 %15, 0
br label %17
17: ; preds = %14, %9
%18 = phi i1 [ false, %9 ], [ %16, %14 ]
br i1 %18, label %19, label %24
19: ; preds = %17
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %6
%22 = load i32, i32* %7
%23 = add nsw i32 %22, -1
store i32 %23, i32* %7
br label %9
24: ; preds = %17
%25 = load i32, i32* %7
%26 = icmp sgt i32 %25, 32
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i32, i32* %7
%29 = icmp slt i32 %28, 1
br i1 %29, label %30, label %31
30: ; preds = %27, %24
store i32 0, i32* %4
br label %44
31: ; preds = %27
%32 = load i32, i32* %7
%33 = sub nsw i32 32, %32
store i32 %33, i32* %8
%34 = load i8*, i8** %5
%35 = load i32, i32* %8
%36 = call i32 @memset(i8* %34, i32 0, i32 %35)
%37 = load i8*, i8** %5
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8*, i8** %6
%42 = load i32, i32* %7
%43 = call i32 @memcpy(i8* %40, i8* %41, i32 %42)
store i32 1, i32* %4
br label %44
44: ; preds = %31, %30
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
define i32 @trim_to_p256_bytes(i8* %0, i8* %1, i32 %2) {
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
%6 = icmp sgt i32 %2, 0
%7 = and i1 %5, %6
br i1 %7, label %8, label %17
8: ; preds = %3, %8
%9 = phi i32 [ %12, %8 ], [ %2, %3 ]
%10 = phi i8* [ %11, %8 ], [ %1, %3 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = add nsw i32 %9, -1
%13 = load i8, i8* %11
%14 = icmp eq i8 %13, 0
%15 = icmp ugt i32 %9, 1
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %8, label %17
17: ; preds = %8, %3
%18 = phi i8* [ %1, %3 ], [ %11, %8 ]
%19 = phi i32 [ %2, %3 ], [ %12, %8 ]
%20 = add i32 %19, -33
%21 = icmp ult i32 %20, -32
br i1 %21, label %28, label %22
22: ; preds = %17
%23 = sub nuw nsw i32 32, %19
%24 = tail call i32 @memset(i8* %0, i32 0, i32 %23)
%25 = zext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = tail call i32 @memcpy(i8* %26, i8* %18, i32 %19)
br label %28
28: ; preds = %17, %22
%29 = phi i32 [ 1, %22 ], [ 0, %17 ]
ret i32 %29
}