#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ md5_stream(int /*<<< orphan*/ *, unsigned int *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
void ipm_get_exec_md5sum(char *exec_md5sum, char *rpath) {
  FILE *fh;
  int i;
  unsigned sbuf[16];
  if (!strcmp(rpath, "unknown")) {
    sprintf(exec_md5sum, "unknown");
  } else {
    fh = fopen(rpath, "rb");
    md5_stream(fh, sbuf);
    fclose(fh);
    for (i = 0; i < 16; ++i)
      sprintf(exec_md5sum + 2 * i, "%02x", sbuf[i]);
  }
}


x86 assembly (clang, -O0):
<ipm_get_exec_md5sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1190 <ipm_get_exec_md5sum+0x40>
mov    -0x8(%rbp),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    1203 <ipm_get_exec_md5sum+0xb3>
mov    -0x10(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1060 <md5_stream@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jge    11fe <ipm_get_exec_md5sum+0xae>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
movslq -0x1c(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edx
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c1 <ipm_get_exec_md5sum+0x71>
jmp    1203 <ipm_get_exec_md5sum+0xb3>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipm_get_exec_md5sum>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     12c5 <ipm_get_exec_md5sum+0x175>
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1060 <md5_stream@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    (%rsp),%edx
lea    0xe66(%rip),%r14
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x2(%r15),%rdi
mov    0x4(%rsp),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x4(%r15),%rdi
mov    0x8(%rsp),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x6(%r15),%rdi
mov    0xc(%rsp),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x8(%r15),%rdi
mov    0x10(%rsp),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0xa(%r15),%rdi
mov    0x14(%rsp),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0xc(%r15),%rdi
mov    0x18(%rsp),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0xe(%r15),%rdi
mov    0x1c(%rsp),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x10(%r15),%rdi
mov    0x20(%rsp),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x12(%r15),%rdi
mov    0x24(%rsp),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x14(%r15),%rdi
mov    0x28(%rsp),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x16(%r15),%rdi
mov    0x2c(%rsp),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x18(%r15),%rdi
mov    0x30(%rsp),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x1a(%r15),%rdi
mov    0x34(%rsp),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x1c(%r15),%rdi
mov    0x38(%rsp),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
add    $0x1e,%r15
mov    0x3c(%rsp),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
jmp    12d2 <ipm_get_exec_md5sum+0x182>
movabs $0x6e776f6e6b6e75,%rax
mov    %rax,(%r15)
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"unknown\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [5 x i8] c"%02x\00"
define void @ipm_get_exec_md5sum(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [16 x i32]
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @strcmp(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%10 = icmp ne i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %40
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %5
%17 = load i32*, i32** %5
%18 = getelementptr inbounds [16 x i32], [16 x i32]* %7, i64 0, i64 0
%19 = call i32 @md5_stream(i32* %17, i32* %18)
%20 = load i32*, i32** %5
%21 = call i32 @fclose(i32* %20)
store i32 0, i32* %6
br label %22
22: ; preds = %36, %14
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 16
br i1 %24, label %25, label %39
25: ; preds = %22
%26 = load i8*, i8** %3
%27 = load i32, i32* %6
%28 = mul nsw i32 2, %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [16 x i32], [16 x i32]* %7, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = call i32 (i8*, i8*, ...) @sprintf(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %25
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %22
39: ; preds = %22
br label %40
40: ; preds = %39, %11
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"unknown\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [5 x i8] c"%02x\00"
define void @ipm_get_exec_md5sum(i8* nocapture writeonly %0, i8* nocapture %1) {
%3 = alloca [16 x i32]
%4 = bitcast [16 x i32]* %3 to i8*
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = bitcast i8* %0 to i64*
store i64 31093567915781749, i64* %8
br label %76
9: ; preds = %2
%10 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 0
%12 = call i32 @md5_stream(i32* %10, i32* %11)
%13 = call i32 @fclose(i32* %10)
%14 = load i32, i32* %11
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds i8, i8* %0, i64 2
%17 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 1
%18 = load i32, i32* %17
%19 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %16, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds i8, i8* %0, i64 4
%21 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 2
%22 = load i32, i32* %21
%23 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %20, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds i8, i8* %0, i64 6
%25 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 3
%26 = load i32, i32* %25
%27 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %24, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds i8, i8* %0, i64 8
%29 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 4
%30 = load i32, i32* %29
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %28, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds i8, i8* %0, i64 10
%33 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 5
%34 = load i32, i32* %33
%35 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %32, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = getelementptr inbounds i8, i8* %0, i64 12
%37 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 6
%38 = load i32, i32* %37
%39 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %36, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds i8, i8* %0, i64 14
%41 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 7
%42 = load i32, i32* %41
%43 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %40, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds i8, i8* %0, i64 16
%45 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 8
%46 = load i32, i32* %45
%47 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %44, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %46)
%48 = getelementptr inbounds i8, i8* %0, i64 18
%49 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 9
%50 = load i32, i32* %49
%51 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %48, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %50)
%52 = getelementptr inbounds i8, i8* %0, i64 20
%53 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 10
%54 = load i32, i32* %53
%55 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %52, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %54)
%56 = getelementptr inbounds i8, i8* %0, i64 22
%57 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 11
%58 = load i32, i32* %57
%59 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %56, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %58)
%60 = getelementptr inbounds i8, i8* %0, i64 24
%61 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 12
%62 = load i32, i32* %61
%63 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %60, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %62)
%64 = getelementptr inbounds i8, i8* %0, i64 26
%65 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 13
%66 = load i32, i32* %65
%67 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %64, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %66)
%68 = getelementptr inbounds i8, i8* %0, i64 28
%69 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 14
%70 = load i32, i32* %69
%71 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %68, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %70)
%72 = getelementptr inbounds i8, i8* %0, i64 30
%73 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 15
%74 = load i32, i32* %73
%75 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %72, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %9, %7
ret void
}