#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*/ time_t;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ P(int);
int /*<<< orphan*/ V(int);
int /*<<< orphan*/ chmod(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int getpid();
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void print_logfile(int hit, int semid, char *contents) {
  time_t now;
  struct tm *ltp;
  FILE *pF;
  P(semid);
  pF = fopen("logfile", "a");
  chmod("logfile", 0777);
  fprintf(pF, "*pid : %d lock -- ", getpid());
  time(&now);
  ltp = localtime(&now);
  if (hit == 0)
    fprintf(pF, "%s-[%d/%d/%d, %d:%d:%d]", contents, (ltp->tm_year) + 1900,
            (ltp->tm_mon) + 1, ltp->tm_mday, ltp->tm_hour, ltp->tm_min,
            ltp->tm_sec);
  else
    fprintf(pF, "%c/%c/%s-[%d/%d/%d, %d:%d:%d]", contents[0], contents[1],
            &contents[2], (ltp->tm_year) + 1900, (ltp->tm_mon) + 1,
            ltp->tm_mday, ltp->tm_hour, ltp->tm_min, ltp->tm_sec);
  fprintf(pF, "-- %d unlock\n", getpid());
  fclose(pF);
  V(semid);
}


x86 assembly (clang, -O0):
<print_logfile>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %edi,-0x14(%rbp)
mov    %esi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <P@plt>
lea    0xe4c(%rip),%rdi
lea    0xe4d(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x38(%rbp)
lea    0xe35(%rip),%rdi
mov    $0x1ff,%esi
call   10a0 <chmod@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    -0x24(%rbp),%rdi
call   1090 <time@plt>
lea    -0x24(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1277 <print_logfile+0xe7>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
add    $0x76c,%ecx
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%r8d
add    $0x1,%r8d
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%r9d
mov    -0x30(%rbp),%rax
mov    0xc(%rax),%r11d
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%r10d
mov    -0x30(%rbp),%rax
mov    0x14(%rax),%eax
lea    0xdc5(%rip),%rsi
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    12ee <print_logfile+0x15e>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rax
movsbl (%rax),%edx
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%ecx
mov    -0x20(%rbp),%r8
add    $0x2,%r8
mov    -0x30(%rbp),%rax
mov    (%rax),%r9d
add    $0x76c,%r9d
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%r14d
add    $0x1,%r14d
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%ebx
mov    -0x30(%rbp),%rax
mov    0xc(%rax),%r11d
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%r10d
mov    -0x30(%rbp),%rax
mov    0x14(%rax),%eax
lea    0xd4c(%rip),%rsi
mov    %r14d,(%rsp)
mov    %ebx,0x8(%rsp)
mov    %r11d,0x10(%rsp)
mov    %r10d,0x18(%rsp)
mov    %eax,0x20(%rsp)
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
lea    0xd31(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x18(%rbp),%edi
call   1050 <V@plt>
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_logfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbp
mov    %esi,%r14d
mov    %edi,%r15d
mov    %esi,%edi
call   1040 <P@plt>
lea    0xe4e(%rip),%rbx
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   10a0 <chmod@plt>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xe2b(%rip),%rsi
mov    %r12,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <time@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
test   %r15d,%r15d
je     1257 <print_logfile+0xc7>
movsbl 0x0(%rbp),%edx
movsbl 0x1(%rbp),%ecx
add    $0x2,%rbp
mov    $0x76c,%r9d
add    (%rax),%r9d
mov    0x4(%rax),%ebx
mov    0x8(%rax),%r10d
add    $0x1,%ebx
mov    0xc(%rax),%r11d
mov    0x10(%rax),%r15d
mov    0x14(%rax),%r13d
sub    $0x8,%rsp
lea    0xde2(%rip),%rsi
mov    %r12,%rdi
mov    %rbp,%r8
xor    %eax,%eax
push   %r13
push   %r15
push   %r11
push   %r10
push   %rbx
call   1080 <fprintf@plt>
add    $0x30,%rsp
jmp    1296 <print_logfile+0x106>
mov    $0x76c,%ecx
add    (%rax),%ecx
mov    0x4(%rax),%r8d
mov    0x8(%rax),%r9d
add    $0x1,%r8d
mov    0xc(%rax),%r10d
mov    0x10(%rax),%r11d
mov    0x14(%rax),%ebx
sub    $0x8,%rsp
lea    0xda3(%rip),%rsi
mov    %r12,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
push   %rbx
push   %r11
push   %r10
call   1080 <fprintf@plt>
add    $0x20,%rsp
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xd97(%rip),%rsi
mov    %r12,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r12,%rdi
call   1070 <fclose@plt>
mov    %r14d,%edi
call   1050 <V@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [8 x i8] c"logfile\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [19 x i8] c"*pid : %d lock -- \00"
@.str.3 = [24 x i8] c"%s-[%d/%d/%d, %d:%d:%d]\00"
@.str.4 = [30 x i8] c"%c/%c/%s-[%d/%d/%d, %d:%d:%d]\00"
@.str.5 = [14 x i8] c"-- %d unlock\0A\00"
define void @print_logfile(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.tm*
%9 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = load i32, i32* %5
%11 = call i32 @P(i32 %10)
%12 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %9
%13 = call i32 @chmod(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 511)
%14 = load i32*, i32** %9
%15 = call i32 (...) @getpid()
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = call i32 @time(i32* %7)
%18 = call %struct.tm* @localtime(i32* %7)
store %struct.tm* %18, %struct.tm** %8
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %45
21: ; preds = %3
%22 = load i32*, i32** %9
%23 = load i8*, i8** %6
%24 = load %struct.tm*, %struct.tm** %8
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 1900
%28 = load %struct.tm*, %struct.tm** %8
%29 = getelementptr inbounds %struct.tm, %struct.tm* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = add nsw i32 %30, 1
%32 = load %struct.tm*, %struct.tm** %8
%33 = getelementptr inbounds %struct.tm, %struct.tm* %32, i32 0, i32 2
%34 = load i32, i32* %33
%35 = load %struct.tm*, %struct.tm** %8
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 3
%37 = load i32, i32* %36
%38 = load %struct.tm*, %struct.tm** %8
%39 = getelementptr inbounds %struct.tm, %struct.tm* %38, i32 0, i32 4
%40 = load i32, i32* %39
%41 = load %struct.tm*, %struct.tm** %8
%42 = getelementptr inbounds %struct.tm, %struct.tm* %41, i32 0, i32 5
%43 = load i32, i32* %42
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %23, i32 %27, i32 %31, i32 %34, i32 %37, i32 %40, i32 %43)
br label %78
45: ; preds = %3
%46 = load i32*, i32** %9
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = load i8*, i8** %6
%52 = getelementptr inbounds i8, i8* %51, i64 1
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = load i8*, i8** %6
%56 = getelementptr inbounds i8, i8* %55, i64 2
%57 = load %struct.tm*, %struct.tm** %8
%58 = getelementptr inbounds %struct.tm, %struct.tm* %57, i32 0, i32 0
%59 = load i32, i32* %58
%60 = add nsw i32 %59, 1900
%61 = load %struct.tm*, %struct.tm** %8
%62 = getelementptr inbounds %struct.tm, %struct.tm* %61, i32 0, i32 1
%63 = load i32, i32* %62
%64 = add nsw i32 %63, 1
%65 = load %struct.tm*, %struct.tm** %8
%66 = getelementptr inbounds %struct.tm, %struct.tm* %65, i32 0, i32 2
%67 = load i32, i32* %66
%68 = load %struct.tm*, %struct.tm** %8
%69 = getelementptr inbounds %struct.tm, %struct.tm* %68, i32 0, i32 3
%70 = load i32, i32* %69
%71 = load %struct.tm*, %struct.tm** %8
%72 = getelementptr inbounds %struct.tm, %struct.tm* %71, i32 0, i32 4
%73 = load i32, i32* %72
%74 = load %struct.tm*, %struct.tm** %8
%75 = getelementptr inbounds %struct.tm, %struct.tm* %74, i32 0, i32 5
%76 = load i32, i32* %75
%77 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %50, i32 %54, i8* %56, i32 %60, i32 %64, i32 %67, i32 %70, i32 %73, i32 %76)
br label %78
78: ; preds = %45, %21
%79 = load i32*, i32** %9
%80 = call i32 (...) @getpid()
%81 = call i32 (i32*, i8*, ...) @fprintf(i32* %79, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %80)
%82 = load i32*, i32** %9
%83 = call i32 @fclose(i32* %82)
%84 = load i32, i32* %5
%85 = call i32 @V(i32 %84)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [8 x i8] c"logfile\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [19 x i8] c"*pid : %d lock -- \00"
@.str.3 = [24 x i8] c"%s-[%d/%d/%d, %d:%d:%d]\00"
@.str.4 = [30 x i8] c"%c/%c/%s-[%d/%d/%d, %d:%d:%d]\00"
@.str.5 = [14 x i8] c"-- %d unlock\0A\00"
define void @print_logfile(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 @P(i32 %1)
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @chmod(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 511)
%9 = tail call i32 (...) @getpid()
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = call i32 @time(i32* %4)
%12 = call %struct.tm* @localtime(i32* %4)
%13 = icmp eq i32 %0, 0
br i1 %13, label %14, label %30
14: ; preds = %3
%15 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 0
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1900
%18 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 1
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
%21 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 2
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 3
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 4
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 5
%28 = load i32, i32* %27
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %2, i32 %17, i32 %20, i32 %22, i32 %24, i32 %26, i32 %28)
br label %52
30: ; preds = %3
%31 = load i8, i8* %2
%32 = sext i8 %31 to i32
%33 = getelementptr inbounds i8, i8* %2, i64 1
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = getelementptr inbounds i8, i8* %2, i64 2
%37 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 0
%38 = load i32, i32* %37
%39 = add nsw i32 %38, 1900
%40 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 1
%41 = load i32, i32* %40
%42 = add nsw i32 %41, 1
%43 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 2
%44 = load i32, i32* %43
%45 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 3
%46 = load i32, i32* %45
%47 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 4
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 5
%50 = load i32, i32* %49
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %32, i32 %35, i8* %36, i32 %39, i32 %42, i32 %44, i32 %46, i32 %48, i32 %50)
br label %52
52: ; preds = %30, %14
%53 = call i32 (...) @getpid()
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %53)
%55 = call i32 @fclose(i32* %7)
%56 = call i32 @V(i32 %1)
ret void
}