#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;

/* Variables and functions */
int ece_hkdf_sha256(int /*<<< orphan*/ const *, size_t,
                    int /*<<< orphan*/ const *, size_t, int /*<<< orphan*/ *,
                    int, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, char *, int);
int ece_aes128gcm_derive_key_and_nonce(const uint8_t *salt, size_t saltLen,
                                       const uint8_t *ikm, size_t ikmLen,
                                       uint8_t *key, uint8_t *nonce) {
  uint8_t keyInfo[28];
  memcpy(keyInfo, "Content-Encoding: aes128gcm\0", 28);
  int err = ece_hkdf_sha256(salt, saltLen, ikm, ikmLen, keyInfo, 28, key, 16);
  if (err) {
    return err;
  }
  uint8_t nonceInfo[24];
  memcpy(nonceInfo, "Content-Encoding: nonce\0", 24);
  return ece_hkdf_sha256(salt, saltLen, ikm, ikmLen, nonceInfo, 24, nonce, 12);
}


x86 assembly (clang, -O0):
<ece_aes128gcm_derive_key_and_nonce>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
lea    -0xb0(%rbp),%rdi
lea    0xeaf(%rip),%rsi
mov    $0x1c,%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    -0xb0(%rbp),%r8
mov    -0x30(%rbp),%rax
mov    $0x1c,%r9d
mov    %rax,(%rsp)
movl   $0x10,0x8(%rsp)
call   1030 <ece_hkdf_sha256@plt>
mov    %eax,-0xb4(%rbp)
cmpl   $0x0,-0xb4(%rbp)
je     11ae <ece_aes128gcm_derive_key_and_nonce+0x8e>
mov    -0xb4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fb <ece_aes128gcm_derive_key_and_nonce+0xdb>
lea    -0x120(%rbp),%rdi
lea    0xe61(%rip),%rsi
mov    $0x18,%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    -0x120(%rbp),%r8
mov    -0x38(%rbp),%rax
mov    $0x18,%r9d
mov    %rax,(%rsp)
movl   $0xc,0x8(%rsp)
call   1030 <ece_hkdf_sha256@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ece_aes128gcm_derive_key_and_nonce>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    %r9,0x8(%rsp)
mov    %r8,%rbp
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbx
lea    0xeb4(%rip),%rsi
lea    0x70(%rsp),%r14
mov    %r14,%rdi
mov    $0x1c,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
mov    $0x1c,%r9d
push   $0x10
push   %rbp
call   1030 <ece_hkdf_sha256@plt>
add    $0x10,%rsp
test   %eax,%eax
jne    11c0 <ece_aes128gcm_derive_key_and_nonce+0xa0>
lea    0xe93(%rip),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x18,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %rbp,%r8
mov    $0x18,%r9d
push   $0xc
push   0x10(%rsp)
call   1030 <ece_hkdf_sha256@plt>
add    $0x10,%rsp
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Content-Encoding: aes128gcm\00\00"
@.str.1 = [25 x i8] c"Content-Encoding: nonce\00\00"
define i32 @ece_aes128gcm_derive_key_and_nonce(i32* %0, i64 %1, i32* %2, i64 %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca [28 x i32]
%15 = alloca i32
%16 = alloca [24 x i32]
store i32* %0, i32** %8
store i64 %1, i64* %9
store i32* %2, i32** %10
store i64 %3, i64* %11
store i32* %4, i32** %12
store i32* %5, i32** %13
%17 = getelementptr inbounds [28 x i32], [28 x i32]* %14, i64 0, i64 0
%18 = call i32 @memcpy(i32* %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 28)
%19 = load i32*, i32** %8
%20 = load i64, i64* %9
%21 = load i32*, i32** %10
%22 = load i64, i64* %11
%23 = getelementptr inbounds [28 x i32], [28 x i32]* %14, i64 0, i64 0
%24 = load i32*, i32** %12
%25 = call i32 @ece_hkdf_sha256(i32* %19, i64 %20, i32* %21, i64 %22, i32* %23, i32 28, i32* %24, i32 16)
store i32 %25, i32* %15
%26 = load i32, i32* %15
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %6
%29 = load i32, i32* %15
store i32 %29, i32* %7
br label %40
30: ; preds = %6
%31 = getelementptr inbounds [24 x i32], [24 x i32]* %16, i64 0, i64 0
%32 = call i32 @memcpy(i32* %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 24)
%33 = load i32*, i32** %8
%34 = load i64, i64* %9
%35 = load i32*, i32** %10
%36 = load i64, i64* %11
%37 = getelementptr inbounds [24 x i32], [24 x i32]* %16, i64 0, i64 0
%38 = load i32*, i32** %13
%39 = call i32 @ece_hkdf_sha256(i32* %33, i64 %34, i32* %35, i64 %36, i32* %37, i32 24, i32* %38, i32 12)
store i32 %39, i32* %7
br label %40
40: ; preds = %30, %28
%41 = load i32, i32* %7
ret i32 %41
}

LLVM IR (-O2):
@.str = [29 x i8] c"Content-Encoding: aes128gcm\00\00"
@.str.1 = [25 x i8] c"Content-Encoding: nonce\00\00"
define i32 @ece_aes128gcm_derive_key_and_nonce(i32* %0, i64 %1, i32* %2, i64 %3, i32* %4, i32* %5) {
%7 = alloca [28 x i32]
%8 = alloca [24 x i32]
%9 = bitcast [28 x i32]* %7 to i8*
%10 = getelementptr inbounds [28 x i32], [28 x i32]* %7, i64 0, i64 0
%11 = call i32 @memcpy(i32* %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 28)
%12 = call i32 @ece_hkdf_sha256(i32* %0, i64 %1, i32* %2, i64 %3, i32* %10, i32 28, i32* %4, i32 16)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %6
%15 = bitcast [24 x i32]* %8 to i8*
%16 = getelementptr inbounds [24 x i32], [24 x i32]* %8, i64 0, i64 0
%17 = call i32 @memcpy(i32* %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 24)
%18 = call i32 @ece_hkdf_sha256(i32* %0, i64 %1, i32* %2, i64 %3, i32* %16, i32 24, i32* %5, i32 12)
br label %19
19: ; preds = %6, %14
%20 = phi i32 [ %18, %14 ], [ %12, %6 ]
ret i32 %20
}