#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 */
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sock_name;
typedef int /*<<< orphan*/ name;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ *MD5(char *, int /*<<< orphan*/, char *);
int MD5_DIGEST_LENGTH;
scalar_t__ getsockname(int, struct sockaddr *, int *);
int /*<<< orphan*/ *inet_ntop(int /*<<< orphan*/, struct sockaddr_in *, char *,
                              int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ shout(char *);
int /*<<< orphan*/ socket_error(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strlen(char *);
int fill_time(int sock, char *buffer, int len, const char *session_id) {
  struct sockaddr_in name;
  char sock_name[256];
  char time_str[256];
  char md5[MD5_DIGEST_LENGTH];
  int sock_len = sizeof(name);
  int i;
  if (len < 33)
    return -1;
  if (getsockname(sock, (struct sockaddr *)&name, &sock_len) < 0) {
    socket_error("getsockname:");
    return -1;
  }
  memset(sock_name, 0, sizeof(sock_name));
  if (inet_ntop(AF_INET, &name, sock_name, sock_len) == NULL) {
    return -1;
  }
  sprintf(time_str, "%s:%s:%s", "liuyan", session_id, sock_name);
  if (MD5(time_str, strlen(time_str), md5) == NULL) {
    shout("md5 error!\n");
    return -1;
  }
  for (i = 0; i < MD5_DIGEST_LENGTH; i++) {
    sprintf(buffer + i * 2, "%2.2X", md5[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<fill_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x238(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x258(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x240(%rbp)
movl   $0x4,-0x244(%rbp)
cmpl   $0x21,-0x14(%rbp)
jge    11f8 <fill_time+0x78>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x24c(%rbp)
jmp    1382 <fill_time+0x202>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x244(%rbp),%rdx
call   1090 <getsockname@plt>
cmp    $0x0,%rax
jge    1237 <fill_time+0xb7>
lea    0xde4(%rip),%rdi
call   1040 <socket_error@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x24c(%rbp)
jmp    1382 <fill_time+0x202>
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
lea    -0x130(%rbp),%rdx
mov    -0x244(%rbp),%ecx
lea    -0x28(%rbp),%rsi
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
jne    1289 <fill_time+0x109>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x24c(%rbp)
jmp    1382 <fill_time+0x202>
lea    -0x230(%rbp),%rdi
mov    -0x20(%rbp),%rcx
lea    -0x130(%rbp),%r8
lea    0xd6b(%rip),%rsi
lea    0xd6d(%rip),%rdx
mov    $0x0,%al
call   10a0 <sprintf@plt>
lea    -0x230(%rbp),%rax
mov    %rax,-0x260(%rbp)
lea    -0x230(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x260(%rbp),%rdi
mov    -0x258(%rbp),%rdx
mov    %eax,%esi
call   1080 <MD5@plt>
cmp    $0x0,%rax
jne    130b <fill_time+0x18b>
lea    0xd2d(%rip),%rdi
call   1070 <shout@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x24c(%rbp)
jmp    1382 <fill_time+0x202>
movl   $0x0,-0x248(%rbp)
mov    -0x248(%rbp),%eax
mov    0x2cb6(%rip),%rcx
cmp    (%rcx),%eax
jge    1371 <fill_time+0x1f1>
mov    -0x258(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x248(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rdi
movslq -0x248(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xcd3(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0x248(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x248(%rbp)
jmp    1315 <fill_time+0x195>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x24c(%rbp)
mov    -0x238(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_time>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rsp,%r13
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
movl   $0x4,-0x2c(%rbp)
mov    $0xffffffff,%r14d
cmp    $0x21,%edx
jl     12df <fill_time+0x15f>
mov    %rcx,%r12
mov    %rsi,%rbx
lea    -0x30(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1090 <getsockname@plt>
test   %rax,%rax
js     12bf <fill_time+0x13f>
lea    -0x240(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%ecx
lea    -0x30(%rbp),%rsi
lea    -0x240(%rbp),%rdx
call   1030 <inet_ntop@plt>
test   %rax,%rax
je     12df <fill_time+0x15f>
lea    0xdeb(%rip),%rsi
lea    0xded(%rip),%rdx
xor    %r14d,%r14d
lea    -0x140(%rbp),%rdi
lea    -0x240(%rbp),%r8
mov    %r12,%rcx
xor    %eax,%eax
call   10a0 <sprintf@plt>
lea    -0x140(%rbp),%rdi
call   1050 <strlen@plt>
lea    -0x140(%rbp),%rdi
mov    %eax,%esi
mov    %r15,%rdx
call   1080 <MD5@plt>
test   %rax,%rax
je     12cd <fill_time+0x14d>
mov    0x2d6b(%rip),%rax
cmpl   $0x0,(%rax)
jle    12df <fill_time+0x15f>
mov    %r13,-0x38(%rbp)
xor    %r14d,%r14d
lea    0xda9(%rip),%r12
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%r15,%r13,1),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   10a0 <sprintf@plt>
add    $0x1,%r13
mov    0x2d2b(%rip),%rax
movslq (%rax),%rax
add    $0x2,%rbx
cmp    %rax,%r13
jl     1290 <fill_time+0x110>
mov    -0x38(%rbp),%r13
jmp    12df <fill_time+0x15f>
lea    0xd3a(%rip),%rdi
call   1040 <socket_error@plt>
jmp    12d9 <fill_time+0x159>
lea    0xd49(%rip),%rdi
call   1070 <shout@plt>
mov    $0xffffffff,%r14d
mov    %r13,%rsp
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@MD5_DIGEST_LENGTH = global i32 0
@.str = [13 x i8] c"getsockname:\00"
@AF_INET = global i32 0
@.str.1 = [9 x i8] c"%s:%s:%s\00"
@.str.2 = [7 x i8] c"liuyan\00"
@.str.3 = [12 x i8] c"md5 error!\0A\00"
@.str.4 = [6 x i8] c"%2.2X\00"
define i32 @fill_time(i32 %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca %struct.sockaddr_in
%11 = alloca [256 x i8]
%12 = alloca [256 x i8]
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%18 = load i32, i32* @MD5_DIGEST_LENGTH
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %13
%21 = alloca i8, i64 %19
store i64 %19, i64* %14
store i32 4, i32* %15
%22 = load i32, i32* %8
%23 = icmp slt i32 %22, 33
br i1 %23, label %24, label %25
24: ; preds = %4
store i32 -1, i32* %5
store i32 1, i32* %17
br label %74
25: ; preds = %4
%26 = load i32, i32* %6
%27 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%28 = call i64 @getsockname(i32 %26, %struct.sockaddr* %27, i32* %15)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @socket_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
store i32 1, i32* %17
br label %74
32: ; preds = %25
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%34 = call i32 @memset(i8* %33, i32 0, i32 256)
%35 = load i32, i32* @AF_INET
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%37 = load i32, i32* %15
%38 = call i32* @inet_ntop(i32 %35, %struct.sockaddr_in* %10, i8* %36, i32 %37)
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %41
40: ; preds = %32
store i32 -1, i32* %5
store i32 1, i32* %17
br label %74
41: ; preds = %32
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%43 = load i8*, i8** %9
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%45 = call i32 (i8*, i8*, ...) @sprintf(i8* %42, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %43, i8* %44)
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%48 = call i32 @strlen(i8* %47)
%49 = call i32* @MD5(i8* %46, i32 %48, i8* %21)
%50 = icmp eq i32* %49, null
br i1 %50, label %51, label %53
51: ; preds = %41
%52 = call i32 @shout(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %5
store i32 1, i32* %17
br label %74
53: ; preds = %41
store i32 0, i32* %16
br label %54
54: ; preds = %70, %53
%55 = load i32, i32* %16
%56 = load i32, i32* @MD5_DIGEST_LENGTH
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %73
58: ; preds = %54
%59 = load i8*, i8** %7
%60 = load i32, i32* %16
%61 = mul nsw i32 %60, 2
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %59, i64 %62
%64 = load i32, i32* %16
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %21, i64 %65
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = call i32 (i8*, i8*, ...) @sprintf(i8* %63, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %68)
br label %70
70: ; preds = %58
%71 = load i32, i32* %16
%72 = add nsw i32 %71, 1
store i32 %72, i32* %16
br label %54
73: ; preds = %54
store i32 0, i32* %5
store i32 1, i32* %17
br label %74
74: ; preds = %73, %51, %40, %30, %24
%75 = load i8*, i8** %13
%76 = load i32, i32* %5
ret i32 %76
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@MD5_DIGEST_LENGTH = global i32 0
@.str = [13 x i8] c"getsockname:\00"
@AF_INET = global i32 0
@.str.1 = [9 x i8] c"%s:%s:%s\00"
@.str.2 = [7 x i8] c"liuyan\00"
@.str.3 = [12 x i8] c"md5 error!\0A\00"
@.str.4 = [6 x i8] c"%2.2X\00"
define i32 @fill_time(i32 %0, i8* nocapture writeonly %1, i32 %2, i8* %3) {
%5 = alloca %struct.sockaddr_in
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%12 = load i32, i32* @MD5_DIGEST_LENGTH
%13 = zext i32 %12 to i64
%14 = tail call i8* @llvm.stacksave()
%15 = alloca i8, i64 %13
%16 = bitcast i32* %8 to i8*
store i32 4, i32* %8
%17 = icmp slt i32 %2, 33
br i1 %17, label %52, label %18
18: ; preds = %4
%19 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%20 = call i64 @getsockname(i32 %0, %struct.sockaddr* %19, i32* %8)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @socket_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %52
24: ; preds = %18
%25 = call i32 @memset(i8* %10, i32 0, i32 256)
%26 = load i32, i32* @AF_INET
%27 = load i32, i32* %8
%28 = call i32* @inet_ntop(i32 %26, %struct.sockaddr_in* %5, i8* %10, i32 %27)
%29 = icmp eq i32* %28, null
br i1 %29, label %52, label %30
30: ; preds = %24
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %3, i8* %10)
%32 = call i32 @strlen(i8* %11)
%33 = call i32* @MD5(i8* %11, i32 %32, i8* %15)
%34 = icmp eq i32* %33, null
br i1 %34, label %38, label %35
35: ; preds = %30
%36 = load i32, i32* @MD5_DIGEST_LENGTH
%37 = icmp sgt i32 %36, 0
br i1 %37, label %40, label %52
38: ; preds = %30
%39 = call i32 @shout(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %52
40: ; preds = %35, %40
%41 = phi i64 [ %48, %40 ], [ 0, %35 ]
%42 = shl nuw nsw i64 %41, 1
%43 = getelementptr inbounds i8, i8* %1, i64 %42
%44 = getelementptr inbounds i8, i8* %15, i64 %41
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %43, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %46)
%48 = add nuw nsw i64 %41, 1
%49 = load i32, i32* @MD5_DIGEST_LENGTH
%50 = sext i32 %49 to i64
%51 = icmp slt i64 %48, %50
br i1 %51, label %40, label %52
52: ; preds = %40, %35, %24, %4, %38, %22
%53 = phi i32 [ -1, %22 ], [ -1, %38 ], [ -1, %4 ], [ -1, %24 ], [ 0, %35 ], [ 0, %40 ]
ret i32 %53
}