#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, char *, int,
                    int /*<<< orphan*/ *, 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) {
  int err = ece_hkdf_sha256(salt, saltLen, ikm, ikmLen,
                            "Content-Encoding: aes128gcm\0", 28, key, 16);
  if (err) {
    return err;
  }
  return ece_hkdf_sha256(salt, saltLen, ikm, ikmLen,
                         "Content-Encoding: nonce\0", 24, nonce, 12);
}


x86 assembly (clang, -O0):
<ece_aes128gcm_derive_key_and_nonce>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%rax
lea    0xeb5(%rip),%r8
mov    $0x1c,%r9d
mov    %rax,(%rsp)
movl   $0x10,0x8(%rsp)
call   1030 <ece_hkdf_sha256@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     117a <ece_aes128gcm_derive_key_and_nonce+0x6a>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11af <ece_aes128gcm_derive_key_and_nonce+0x9f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x38(%rbp),%rax
lea    0xe88(%rip),%r8
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    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ece_aes128gcm_derive_key_and_nonce>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %r9,%r14
mov    %r8,%rax
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbx
lea    0xece(%rip),%r8
mov    $0x1c,%r9d
push   $0x10
push   %rax
call   1030 <ece_hkdf_sha256@plt>
add    $0x10,%rsp
test   %eax,%eax
jne    116e <ece_aes128gcm_derive_key_and_nonce+0x5e>
lea    0xece(%rip),%r8
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    $0x18,%r9d
push   $0xc
push   %r14
call   1030 <ece_hkdf_sha256@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
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 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
%15 = load i32*, i32** %8
%16 = load i64, i64* %9
%17 = load i32*, i32** %10
%18 = load i64, i64* %11
%19 = load i32*, i32** %12
%20 = call i32 @ece_hkdf_sha256(i32* %15, i64 %16, i32* %17, i64 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 28, i32* %19, i32 16)
store i32 %20, i32* %14
%21 = load i32, i32* %14
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %6
%24 = load i32, i32* %14
store i32 %24, i32* %7
br label %32
25: ; preds = %6
%26 = load i32*, i32** %8
%27 = load i64, i64* %9
%28 = load i32*, i32** %10
%29 = load i64, i64* %11
%30 = load i32*, i32** %13
%31 = call i32 @ece_hkdf_sha256(i32* %26, i64 %27, i32* %28, i64 %29, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 24, i32* %30, i32 12)
store i32 %31, i32* %7
br label %32
32: ; preds = %25, %23
%33 = load i32, i32* %7
ret i32 %33
}

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 = tail call i32 @ece_hkdf_sha256(i32* %0, i64 %1, i32* %2, i64 %3, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 28, i32* %4, i32 16)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @ece_hkdf_sha256(i32* %0, i64 %1, i32* %2, i64 %3, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 24, i32* %5, i32 12)
br label %11
11: ; preds = %6, %9
%12 = phi i32 [ %10, %9 ], [ %7, %6 ]
ret i32 %12
}