#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 */
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int write_conflict_log(char *fullname, int type, char *msg) {
  printf("write_conflict_log() - start\n");
  FILE *fp = 0;
  char ctype[16] = {0};
  if (type == 1)
    strcpy(ctype, "Error");
  else if (type == 2)
    strcpy(ctype, "Info");
  else if (type == 3)
    strcpy(ctype, "Warning");
  if (access("/tmp/smartsync/.logs/sambaclient_errlog", 0) == 0)
    fp = fopen("/tmp/smartsync/.logs/sambaclient_errlog", "a");
  else
    fp = fopen("/tmp/smartsync/.logs/sambaclient_errlog", "w");
  if (fp == NULL) {
    printf("open %s fail\n", "/tmp/smartsync/.logs/sambaclient_errlog");
    return -1;
  }
  printf("TYPE:%s\nUSERNAME:%s\nFILENAME:%s\nMESSAGE:%s\n", ctype, "NULL",
         fullname, msg);
  fclose(fp);
  printf("write_conflict_log() - end\n");
  return 0;
}


x86 assembly (clang, -O0):
<write_conflict_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x28(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
cmpl   $0x1,-0x14(%rbp)
jne    11b8 <write_conflict_log+0x58>
lea    -0x40(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11fb <write_conflict_log+0x9b>
cmpl   $0x2,-0x14(%rbp)
jne    11d7 <write_conflict_log+0x77>
lea    -0x40(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11f6 <write_conflict_log+0x96>
cmpl   $0x3,-0x14(%rbp)
jne    11f1 <write_conflict_log+0x91>
lea    -0x40(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11f6 <write_conflict_log+0x96>
jmp    11fb <write_conflict_log+0x9b>
lea    0xe2f(%rip),%rdi
xor    %esi,%esi
call   1070 <access@plt>
cmp    $0x0,%rax
jne    122f <write_conflict_log+0xcf>
lea    0xe17(%rip),%rdi
lea    0xe38(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
jmp    1246 <write_conflict_log+0xe6>
lea    0xdfb(%rip),%rdi
lea    0xe1e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1272 <write_conflict_log+0x112>
lea    0xe05(%rip),%rdi
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b1 <write_conflict_log+0x151>
lea    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xde6(%rip),%rdi
lea    0xe0b(%rip),%rdx
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_conflict_log>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rdi,%r15
lea    0xf05(%rip),%rdi
call   1040 <puts@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
add    $0xffffffff,%ebx
cmp    $0x2,%ebx
ja     11a6 <write_conflict_log+0x46>
movslq %ebx,%rax
lea    0xf21(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
lea    0xe66(%rip),%rbx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <access@plt>
test   %rax,%rax
lea    0xe78(%rip),%rax
lea    0xe73(%rip),%rsi
cmove  %rax,%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1212 <write_conflict_log+0xb2>
mov    %rax,%rbx
lea    0xe68(%rip),%rdi
lea    0xe8d(%rip),%rdx
mov    %rsp,%rsi
mov    %r15,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xe90(%rip),%rdi
call   1040 <puts@plt>
jmp    122c <write_conflict_log+0xcc>
lea    0xe26(%rip),%rdi
lea    0xdf3(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"write_conflict_log() - start\0A\00"
@.str.1 = [6 x i8] c"Error\00"
@.str.2 = [5 x i8] c"Info\00"
@.str.3 = [8 x i8] c"Warning\00"
@.str.4 = [40 x i8] c"/tmp/smartsync/.logs/sambaclient_errlog\00"
@.str.5 = [2 x i8] c"a\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [14 x i8] c"open %s fail\0A\00"
@.str.8 = [44 x i8] c"TYPE:%s\0AUSERNAME:%s\0AFILENAME:%s\0AMESSAGE:%s\0A\00"
@.str.9 = [5 x i8] c"NULL\00"
@.str.10 = [28 x i8] c"write_conflict_log() - end\0A\00"
define i32 @write_conflict_log(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca [16 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32* null, i32** %8
%11 = bitcast [16 x i8]* %9 to i8*
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %31
17: ; preds = %3
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %30
23: ; preds = %17
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 3
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%28 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %26, %23
br label %30
30: ; preds = %29, %20
br label %31
31: ; preds = %30, %14
%32 = call i64 @access(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 0)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32* @fopen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %35, i32** %8
br label %38
36: ; preds = %31
%37 = call i32* @fopen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %37, i32** %8
br label %38
38: ; preds = %36, %34
%39 = load i32*, i32** %8
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %4
br label %51
43: ; preds = %38
%44 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%45 = load i8*, i8** %5
%46 = load i8*, i8** %7
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.8, i64 0, i64 0), i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* %45, i8* %46)
%48 = load i32*, i32** %8
%49 = call i32 @fclose(i32* %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %4
br label %51
51: ; preds = %43, %41
%52 = load i32, i32* %4
ret i32 %52
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"Error\00"
@.str.2 = [5 x i8] c"Info\00"
@.str.3 = [8 x i8] c"Warning\00"
@.str.4 = [40 x i8] c"/tmp/smartsync/.logs/sambaclient_errlog\00"
@.str.5 = [2 x i8] c"a\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [14 x i8] c"open %s fail\0A\00"
@.str.8 = [44 x i8] c"TYPE:%s\0AUSERNAME:%s\0AFILENAME:%s\0AMESSAGE:%s\0A\00"
@.str.9 = [5 x i8] c"NULL\00"
@str = [29 x i8] c"write_conflict_log() - start\00"
@str.11 = [27 x i8] c"write_conflict_log() - end\00"
@reltable.write_conflict_log = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.write_conflict_log to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.write_conflict_log to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.3 to i64), i64 ptrtoint ([3 x i32]* @reltable.write_conflict_log to i64)) to i32)]
define i32 @write_conflict_log(i8* %0, i32 %1, i8* %2) {
%4 = alloca [16 x i8]
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%7 = add i32 %1, -1
%8 = icmp ult i32 %7, 3
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = sext i32 %7 to i64
%11 = shl i64 %10, 2
%12 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.write_conflict_log to i8*), i64 %11)
%13 = call i32 @strcpy(i8* %6, i8* %12)
br label %14
14: ; preds = %3, %9
%15 = call i64 @access(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 0)
%16 = icmp eq i64 %15, 0
%17 = select i1 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0)
%18 = call i32* @fopen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %17)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %26
22: ; preds = %14
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.8, i64 0, i64 0), i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* %0, i8* %2)
%24 = call i32 @fclose(i32* %18)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.11, i64 0, i64 0))
br label %26
26: ; preds = %22, %20
%27 = phi i32 [ -1, %20 ], [ 0, %22 ]
ret i32 %27
}