#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 */
char *ctime(long *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *,
                           char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
long time(int /*<<< orphan*/);
int gl_site_msg(char *from, char *to, char *msg) {
  FILE *f;
  char buf[300], *p;
  long t;
  if (!to)
    return 0;
  sprintf(buf, "%s/%s", "/ftp-data/msgs", to);
  f = fopen(buf, "a");
  if (!f)
    return 0;
  t = time(0);
  sprintf(buf, "%s", ctime(&t));
  p = (char *)&buf;
  while (*p)
    if (*p == '\n')
      *p = 0;
    else
      p++;
  fprintf(f,
          "From: %s "
          "(%s)----------------------------------------------------------------"
          "----------%s",
          from, buf, msg);
  fclose(f);
  return 1;
}


x86 assembly (clang, -O0):
<gl_site_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118e <gl_site_msg+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    12a2 <gl_site_msg+0x142>
lea    -0x160(%rbp),%rdi
mov    -0x18(%rbp),%rcx
lea    0xe60(%rip),%rsi
lea    0xe5f(%rip),%rdx
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x160(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11dc <gl_site_msg+0x7c>
movl   $0x0,-0x4(%rbp)
jmp    12a2 <gl_site_msg+0x142>
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,-0x170(%rbp)
lea    -0x160(%rbp),%rax
mov    %rax,-0x178(%rbp)
lea    -0x170(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0x178(%rbp),%rdi
mov    %rax,%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x160(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    -0x168(%rbp),%rax
cmpb   $0x0,(%rax)
je     1273 <gl_site_msg+0x113>
mov    -0x168(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    125c <gl_site_msg+0xfc>
mov    -0x168(%rbp),%rax
movb   $0x0,(%rax)
jmp    126e <gl_site_msg+0x10e>
mov    -0x168(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x168(%rbp)
jmp    122a <gl_site_msg+0xca>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x160(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xd8a(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gl_site_msg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x140,%rsp
test   %rsi,%rsi
je     1203 <gl_site_msg+0x93>
mov    %rdx,%r14
mov    %rsi,%rcx
mov    %rdi,%r15
lea    0xe6c(%rip),%rsi
lea    0xe6b(%rip),%rdx
xor    %ebp,%ebp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1090 <sprintf@plt>
lea    0xe62(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     122e <gl_site_msg+0xbe>
mov    %rax,%r12
xor    %edi,%edi
call   1070 <time@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1050 <ctime@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    (%rbx),%al
cmp    $0xa,%al
jne    11f9 <gl_site_msg+0x89>
nopw   0x0(%rax,%rax,1)
movb   $0x0,(%rbx)
xor    %eax,%eax
cmp    $0xa,%al
je     11f0 <gl_site_msg+0x80>
test   %al,%al
je     1207 <gl_site_msg+0x97>
add    $0x1,%rbx
jmp    11e4 <gl_site_msg+0x74>
xor    %ebp,%ebp
jmp    122e <gl_site_msg+0xbe>
lea    0xe09(%rip),%rsi
lea    0x10(%rsp),%rcx
mov    %r12,%rdi
mov    %r15,%rdx
mov    %r14,%r8
call   1060 <fprintf@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x140,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [15 x i8] c"/ftp-data/msgs\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [90 x i8] c"From: %s (%s)--------------------------------------------------------------------------%s\00"
define i32 @gl_site_msg(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca [300 x i8]
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %3
store i32 0, i32* %4
br label %53
15: ; preds = %3
%16 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%17 = load i8*, i8** %6
%18 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %20, i32** %8
%21 = load i32*, i32** %8
%22 = icmp ne i32* %21, null
br i1 %22, label %24, label %23
23: ; preds = %15
store i32 0, i32* %4
br label %53
24: ; preds = %15
%25 = call i64 @time(i32 0)
store i64 %25, i64* %11
%26 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%27 = call i8* @ctime(i64* %11)
%28 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = bitcast [300 x i8]* %9 to i8*
store i8* %29, i8** %10
br label %30
30: ; preds = %44, %24
%31 = load i8*, i8** %10
%32 = load i8, i8* %31
%33 = icmp ne i8 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %30
%35 = load i8*, i8** %10
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 10
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = load i8*, i8** %10
store i8 0, i8* %40
br label %44
41: ; preds = %34
%42 = load i8*, i8** %10
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %10
br label %44
44: ; preds = %41, %39
br label %30
45: ; preds = %30
%46 = load i32*, i32** %8
%47 = load i8*, i8** %5
%48 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%49 = load i8*, i8** %7
%50 = call i32 @fprintf(i32* %46, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.4, i64 0, i64 0), i8* %47, i8* %48, i8* %49)
%51 = load i32*, i32** %8
%52 = call i32 @fclose(i32* %51)
store i32 1, i32* %4
br label %53
53: ; preds = %45, %23, %14
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [15 x i8] c"/ftp-data/msgs\00"
@.str.2 = [2 x i8] c"a\00"
@.str.4 = [90 x i8] c"From: %s (%s)--------------------------------------------------------------------------%s\00"
define i32 @gl_site_msg(i8* %0, i8* %1, i8* %2) {
%4 = alloca [300 x i8]
%5 = alloca i64
%6 = getelementptr inbounds [300 x i8], [300 x i8]* %4, i64 0, i64 0
%7 = bitcast i64* %5 to i8*
%8 = icmp eq i8* %1, null
br i1 %8, label %28, label %9
9: ; preds = %3
%10 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%11 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %28, label %13
13: ; preds = %9
%14 = tail call i64 @time(i32 0)
store i64 %14, i64* %5
%15 = call i8* @ctime(i64* %5)
%16 = call i8* @strcpy(i8* %6, i8* dereferenceable(1) %15)
br label %17
17: ; preds = %23, %13
%18 = phi i8* [ %24, %23 ], [ %6, %13 ]
%19 = load i8, i8* %18
br label %20
20: ; preds = %17, %22
%21 = phi i8 [ %19, %17 ], [ 0, %22 ]
switch i8 %21, label %23 [
i8 0, label %25
i8 10, label %22
]
22: ; preds = %20
store i8 0, i8* %18
br label %20
23: ; preds = %20
%24 = getelementptr inbounds i8, i8* %18, i64 1
br label %17
25: ; preds = %20
%26 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %6, i8* %2)
%27 = call i32 @fclose(i32* %11)
br label %28
28: ; preds = %9, %3, %25
%29 = phi i32 [ 1, %25 ], [ 0, %3 ], [ 0, %9 ]
ret i32 %29
}