#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*/ qop;
typedef int /*<<< orphan*/ ha1;
typedef int /*<<< orphan*/ cnonce;

/* Variables and functions */
int /*<<< orphan*/ mkmd5resp(char const *, scalar_t__, char const *, scalar_t__,
                             char *, int, char *, scalar_t__, char *,
                             size_t const, char *, scalar_t__, char const *,
                             int, char *);
int /*<<< orphan*/ ns_md5(char *, char const *, size_t, char const *,
                          size_t const, char const *, size_t, char const *,
                          size_t const, char const *, size_t,
                          int /*<<< orphan*/ *);
int snprintf(char *, size_t, char *, ...);
scalar_t__ strlen(char const *);
scalar_t__ time(int /*<<< orphan*/ *);
int ns_http_create_digest_auth_header(char *buf, size_t buf_len,
                                      const char *method, const char *uri,
                                      const char *auth_domain, const char *user,
                                      const char *passwd) {
  static const char colon[] = ":", qop[] = "auth";
  static const size_t one = 1;
  char ha1[33], resp[33], cnonce[40];
  snprintf(cnonce, sizeof(cnonce), "%x", (unsigned int)time(NULL));
  ns_md5(ha1, user, (size_t)strlen(user), colon, one, auth_domain,
         (size_t)strlen(auth_domain), colon, one, passwd,
         (size_t)strlen(passwd), NULL);
  mkmd5resp(method, strlen(method), uri, strlen(uri), ha1, sizeof(ha1) - 1,
            cnonce, strlen(cnonce), "1", one, cnonce, strlen(cnonce), qop,
            sizeof(qop) - 1, resp);
  return snprintf(buf, buf_len,
                  "Authorization: Digest username=\"%s\","
                  "realm=\"%s\",uri=\"%s\",qop=%s,nc=1,cnonce=%s,"
                  "nonce=%s,response=%s\r\n",
                  user, auth_domain, uri, qop, cnonce, cnonce, resp);
}


x86 assembly (clang, -O0):
<ns_http_create_digest_auth_header>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x160,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
mov    %rdx,-0x38(%rbp)
mov    %rcx,-0x40(%rbp)
mov    %r8,-0x48(%rbp)
mov    %r9,-0x50(%rbp)
lea    -0xe0(%rbp),%rax
mov    %rax,-0x138(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    -0x138(%rbp),%rdi
mov    %eax,%ecx
mov    $0x28,%esi
lea    0xe66(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x80(%rbp),%rax
mov    %rax,-0x130(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x120(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    0x10(%rbp),%rax
mov    %rax,-0x110(%rbp)
mov    0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x130(%rbp),%rdi
mov    -0x128(%rbp),%rsi
mov    -0x120(%rbp),%rdx
mov    -0x118(%rbp),%r9
mov    -0x110(%rbp),%r10
lea    0xdd4(%rip),%r11
mov    $0x1,%r8d
xor    %ecx,%ecx
mov    %r11,%rcx
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
movq   $0x1,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
movq   $0x0,0x28(%rsp)
call   1060 <ns_md5@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x100(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0xf0(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0xe8(%rbp)
lea    -0xe0(%rbp),%r12
lea    -0xe0(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
lea    -0xe0(%rbp),%rbx
lea    -0xe0(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x108(%rbp),%rdi
mov    -0x100(%rbp),%rsi
mov    -0xf8(%rbp),%rdx
mov    -0xf0(%rbp),%rcx
mov    -0xe8(%rbp),%r8
mov    %rax,%r11
lea    -0xb0(%rbp),%rax
mov    $0x20,%r9d
lea    0xd0e(%rip),%r14
lea    0xcf6(%rip),%r10
mov    %r12,(%rsp)
mov    %r15,0x8(%rsp)
mov    %r14,0x10(%rsp)
movq   $0x1,0x18(%rsp)
mov    %rbx,0x20(%rsp)
mov    %r11,0x28(%rsp)
mov    %r10,0x30(%rsp)
movl   $0x4,0x38(%rsp)
mov    %rax,0x40(%rsp)
call   1070 <mkmd5resp@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x40(%rbp),%r9
lea    -0xe0(%rbp),%r11
lea    -0xe0(%rbp),%r10
lea    -0xb0(%rbp),%rax
lea    0xca1(%rip),%rdx
lea    0xc87(%rip),%rbx
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
mov    $0x0,%al
call   1040 <snprintf@plt>
add    $0x160,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<ns_http_create_digest_auth_header>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %r9,%r15
mov    %r8,%rbp
mov    %rcx,%r12
mov    %rdx,(%rsp)
mov    %rsi,0x18(%rsp)
mov    %rdi,0x10(%rsp)
mov    0xe0(%rsp),%r14
xor    %edi,%edi
call   1050 <time@plt>
lea    0xe79(%rip),%rdx
lea    0x50(%rsp),%rdi
mov    $0x28,%esi
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
mov    %rbp,%rdi
mov    %rbp,0x8(%rsp)
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0xe35(%rip),%rcx
lea    0x20(%rsp),%rdi
mov    $0x1,%r8d
mov    %r15,%rsi
mov    %r13,%rdx
mov    %rbp,%r9
push   $0x0
push   %rax
push   %r14
push   $0x1
push   %rcx
push   %rbx
call   1060 <ns_md5@plt>
add    $0x30,%rsp
mov    (%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbp
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
lea    0x50(%rsp),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
sub    $0x8,%rsp
lea    0x88(%rsp),%r10
lea    0xdd7(%rip),%r11
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
lea    0x28(%rsp),%r8
mov    $0x20,%r9d
push   %r10
mov    %r10,%r13
push   $0x4
push   %r11
push   %rax
push   %r14
push   $0x1
lea    0xdb3(%rip),%rbx
push   %rbx
push   %rax
push   %r14
call   1070 <mkmd5resp@plt>
add    $0x50,%rsp
lea    0xda1(%rip),%rdx
mov    0x10(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    %r15,%rcx
mov    0x8(%rsp),%r8
mov    %r12,%r9
xor    %eax,%eax
push   %r13
push   %r14
push   %r14
lea    0xd73(%rip),%rbp
push   %rbp
call   1040 <snprintf@plt>
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ns_http_create_digest_auth_header.colon = internal constant [2 x i8] c":\00"
@ns_http_create_digest_auth_header.qop = internal constant [5 x i8] c"auth\00"
@ns_http_create_digest_auth_header.one = internal constant i64 1
@.str = [3 x i8] c"%x\00"
@.str.1 = [2 x i8] c"1\00"
@.str.2 = [101 x i8] c"Authorization: Digest username=\22%s\22,realm=\22%s\22,uri=\22%s\22,qop=%s,nc=1,cnonce=%s,nonce=%s,response=%s\0D\0A\00"
define i32 @ns_http_create_digest_auth_header(i8* %0, i64 %1, i8* %2, i8* %3, i8* %4, i8* %5, i8* %6) {
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca [33 x i8]
%16 = alloca [33 x i8]
%17 = alloca [40 x i8]
store i8* %0, i8** %8
store i64 %1, i64* %9
store i8* %2, i8** %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i8* %6, i8** %14
%18 = getelementptr inbounds [40 x i8], [40 x i8]* %17, i64 0, i64 0
%19 = call i64 @time(i32* null)
%20 = trunc i64 %19 to i32
%21 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %18, i64 40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [33 x i8], [33 x i8]* %15, i64 0, i64 0
%23 = load i8*, i8** %13
%24 = load i8*, i8** %13
%25 = call i64 @strlen(i8* %24)
%26 = load i8*, i8** %12
%27 = load i8*, i8** %12
%28 = call i64 @strlen(i8* %27)
%29 = load i8*, i8** %14
%30 = load i8*, i8** %14
%31 = call i64 @strlen(i8* %30)
%32 = call i32 @ns_md5(i8* %22, i8* %23, i64 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @ns_http_create_digest_auth_header.colon, i64 0, i64 0), i64 1, i8* %26, i64 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @ns_http_create_digest_auth_header.colon, i64 0, i64 0), i64 1, i8* %29, i64 %31, i32* null)
%33 = load i8*, i8** %10
%34 = load i8*, i8** %10
%35 = call i64 @strlen(i8* %34)
%36 = load i8*, i8** %11
%37 = load i8*, i8** %11
%38 = call i64 @strlen(i8* %37)
%39 = getelementptr inbounds [33 x i8], [33 x i8]* %15, i64 0, i64 0
%40 = getelementptr inbounds [40 x i8], [40 x i8]* %17, i64 0, i64 0
%41 = getelementptr inbounds [40 x i8], [40 x i8]* %17, i64 0, i64 0
%42 = call i64 @strlen(i8* %41)
%43 = getelementptr inbounds [40 x i8], [40 x i8]* %17, i64 0, i64 0
%44 = getelementptr inbounds [40 x i8], [40 x i8]* %17, i64 0, i64 0
%45 = call i64 @strlen(i8* %44)
%46 = getelementptr inbounds [33 x i8], [33 x i8]* %16, i64 0, i64 0
%47 = call i32 @mkmd5resp(i8* %33, i64 %35, i8* %36, i64 %38, i8* %39, i32 32, i8* %40, i64 %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i64 1, i8* %43, i64 %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @ns_http_create_digest_auth_header.qop, i64 0, i64 0), i32 4, i8* %46)
%48 = load i8*, i8** %8
%49 = load i64, i64* %9
%50 = load i8*, i8** %13
%51 = load i8*, i8** %12
%52 = load i8*, i8** %11
%53 = getelementptr inbounds [40 x i8], [40 x i8]* %17, i64 0, i64 0
%54 = getelementptr inbounds [40 x i8], [40 x i8]* %17, i64 0, i64 0
%55 = getelementptr inbounds [33 x i8], [33 x i8]* %16, i64 0, i64 0
%56 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %48, i64 %49, i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str.2, i64 0, i64 0), i8* %50, i8* %51, i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @ns_http_create_digest_auth_header.qop, i64 0, i64 0), i8* %53, i8* %54, i8* %55)
ret i32 %56
}

LLVM IR (-O2):
@ns_http_create_digest_auth_header.colon = internal constant [2 x i8] c":\00"
@ns_http_create_digest_auth_header.qop = internal constant [5 x i8] c"auth\00"
@.str = [3 x i8] c"%x\00"
@.str.1 = [2 x i8] c"1\00"
@.str.2 = [101 x i8] c"Authorization: Digest username=\22%s\22,realm=\22%s\22,uri=\22%s\22,qop=%s,nc=1,cnonce=%s,nonce=%s,response=%s\0D\0A\00"
define i32 @ns_http_create_digest_auth_header(i8* nocapture writeonly %0, i64 %1, i8* %2, i8* %3, i8* %4, i8* %5, i8* %6) {
%8 = alloca [33 x i8]
%9 = alloca [33 x i8]
%10 = alloca [40 x i8]
%11 = getelementptr inbounds [33 x i8], [33 x i8]* %8, i64 0, i64 0
%12 = getelementptr inbounds [33 x i8], [33 x i8]* %9, i64 0, i64 0
%13 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%14 = tail call i64 @time(i32* null)
%15 = trunc i64 %14 to i32
%16 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %13, i64 40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%18 = tail call i64 @strlen(i8* dereferenceable(1) %4)
%19 = tail call i64 @strlen(i8* dereferenceable(1) %6)
%20 = call i32 @ns_md5(i8* %11, i8* %5, i64 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @ns_http_create_digest_auth_header.colon, i64 0, i64 0), i64 1, i8* %4, i64 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @ns_http_create_digest_auth_header.colon, i64 0, i64 0), i64 1, i8* %6, i64 %19, i32* null)
%21 = call i64 @strlen(i8* dereferenceable(1) %2)
%22 = call i64 @strlen(i8* dereferenceable(1) %3)
%23 = call i64 @strlen(i8* %13)
%24 = call i32 @mkmd5resp(i8* %2, i64 %21, i8* %3, i64 %22, i8* %11, i32 32, i8* %13, i64 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i64 1, i8* %13, i64 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @ns_http_create_digest_auth_header.qop, i64 0, i64 0), i32 4, i8* %12)
%25 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str.2, i64 0, i64 0), i8* %5, i8* %4, i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @ns_http_create_digest_auth_header.qop, i64 0, i64 0), i8* %13, i8* %13, i8* %12)
ret i32 %25
}