#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*/ SHA_CTX;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int SHA1_Update(int /*<<< orphan*/ *, void const *, size_t);
size_t fwrite(void const *, size_t, size_t, int /*<<< orphan*/ *);
size_t fwriteUpdateSha1(const void *p, size_t size, size_t nmemb, FILE *fp,
                        SHA_CTX *c) {
  if (p == NULL || c == NULL)
    return 0;
  if (SHA1_Update(c, p, size * nmemb) != 1)
    return 0;
  return fwrite(p, size, nmemb, fp);
}


x86 assembly (clang, -O0):
<fwriteUpdateSha1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1152 <fwriteUpdateSha1+0x32>
cmpq   $0x0,-0x30(%rbp)
jne    115f <fwriteUpdateSha1+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    11a4 <fwriteUpdateSha1+0x84>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
imul   -0x20(%rbp),%rdx
call   1030 <SHA1_Update@plt>
cmp    $0x1,%eax
je     118b <fwriteUpdateSha1+0x6b>
movq   $0x0,-0x8(%rbp)
jmp    11a4 <fwriteUpdateSha1+0x84>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <fwrite@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwriteUpdateSha1>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     116e <fwriteUpdateSha1+0x4e>
test   %r8,%r8
je     116e <fwriteUpdateSha1+0x4e>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
imul   %rsi,%rdx
mov    %r8,%rdi
mov    %rbx,%rsi
call   1030 <SHA1_Update@plt>
cmp    $0x1,%eax
jne    116e <fwriteUpdateSha1+0x4e>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <fwrite@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @fwriteUpdateSha1(i8* %0, i64 %1, i64 %2, i32* %3, i32* %4) {
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i32*
store i8* %0, i8** %7
store i64 %1, i64* %8
store i64 %2, i64* %9
store i32* %3, i32** %10
store i32* %4, i32** %11
%12 = load i8*, i8** %7
%13 = icmp eq i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %5
%15 = load i32*, i32** %11
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %14, %5
store i64 0, i64* %6
br label %33
18: ; preds = %14
%19 = load i32*, i32** %11
%20 = load i8*, i8** %7
%21 = load i64, i64* %8
%22 = load i64, i64* %9
%23 = mul i64 %21, %22
%24 = call i32 @SHA1_Update(i32* %19, i8* %20, i64 %23)
%25 = icmp ne i32 %24, 1
br i1 %25, label %26, label %27
26: ; preds = %18
store i64 0, i64* %6
br label %33
27: ; preds = %18
%28 = load i8*, i8** %7
%29 = load i64, i64* %8
%30 = load i64, i64* %9
%31 = load i32*, i32** %10
%32 = call i64 @fwrite(i8* %28, i64 %29, i64 %30, i32* %31)
store i64 %32, i64* %6
br label %33
33: ; preds = %27, %26, %17
%34 = load i64, i64* %6
ret i64 %34
}

LLVM IR (-O2):
define i64 @fwriteUpdateSha1(i8* %0, i64 %1, i64 %2, i32* nocapture %3, i32* %4) {
%6 = icmp eq i8* %0, null
%7 = icmp eq i32* %4, null
%8 = or i1 %6, %7
br i1 %8, label %15, label %9
9: ; preds = %5
%10 = mul i64 %2, %1
%11 = tail call i32 @SHA1_Update(i32* %4, i8* %0, i64 %10)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i64 @fwrite(i8* %0, i64 %1, i64 %2, i32* %3)
br label %15
15: ; preds = %9, %5, %13
%16 = phi i64 [ %14, %13 ], [ 0, %5 ], [ 0, %9 ]
ret i64 %16
}