#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*/ strcpy(char *, char *);
int write_conflict_log(char *fullname, int type, char *msg) {
  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) {
    return -1;
  }
  fclose(fp);
  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)
movq   $0x0,-0x28(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
cmpl   $0x1,-0x14(%rbp)
jne    119a <write_conflict_log+0x4a>
lea    -0x40(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11dd <write_conflict_log+0x8d>
cmpl   $0x2,-0x14(%rbp)
jne    11b9 <write_conflict_log+0x69>
lea    -0x40(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11d8 <write_conflict_log+0x88>
cmpl   $0x3,-0x14(%rbp)
jne    11d3 <write_conflict_log+0x83>
lea    -0x40(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11d8 <write_conflict_log+0x88>
jmp    11dd <write_conflict_log+0x8d>
lea    0xe2f(%rip),%rdi
xor    %esi,%esi
call   1060 <access@plt>
cmp    $0x0,%rax
jne    1211 <write_conflict_log+0xc1>
lea    0xe17(%rip),%rdi
lea    0xe38(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
jmp    1228 <write_conflict_log+0xd8>
lea    0xdfb(%rip),%rdi
lea    0xe1e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    123f <write_conflict_log+0xef>
movl   $0xffffffff,-0x4(%rbp)
jmp    124f <write_conflict_log+0xff>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_conflict_log>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
add    $0xffffffff,%esi
cmp    $0x2,%esi
ja     116f <write_conflict_log+0x2f>
movslq %esi,%rax
lea    0xee0(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
lea    0xe9d(%rip),%r14
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <access@plt>
test   %rax,%rax
lea    0xeaf(%rip),%rax
lea    0xeaa(%rip),%rsi
cmove  %rax,%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ae <write_conflict_log+0x6e>
mov    %rax,%rdi
call   1040 <fclose@plt>
jmp    11b3 <write_conflict_log+0x73>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"Error\00"
@.str.1 = [5 x i8] c"Info\00"
@.str.2 = [8 x i8] c"Warning\00"
@.str.3 = [40 x i8] c"/tmp/smartsync/.logs/sambaclient_errlog\00"
@.str.4 = [2 x i8] c"a\00"
@.str.5 = [2 x i8] c"w\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
store i32* null, i32** %8
%10 = bitcast [16 x i8]* %9 to i8*
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %30
16: ; preds = %3
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %29
22: ; preds = %16
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 3
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%27 = call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %25, %22
br label %29
29: ; preds = %28, %19
br label %30
30: ; preds = %29, %13
%31 = call i64 @access(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 0)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32* @fopen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %34, i32** %8
br label %37
35: ; preds = %30
%36 = call i32* @fopen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %36, i32** %8
br label %37
37: ; preds = %35, %33
%38 = load i32*, i32** %8
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %41
40: ; preds = %37
store i32 -1, i32* %4
br label %44
41: ; preds = %37
%42 = load i32*, i32** %8
%43 = call i32 @fclose(i32* %42)
store i32 0, i32* %4
br label %44
44: ; preds = %41, %40
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@.str = [6 x i8] c"Error\00"
@.str.1 = [5 x i8] c"Info\00"
@.str.2 = [8 x i8] c"Warning\00"
@.str.3 = [40 x i8] c"/tmp/smartsync/.logs/sambaclient_errlog\00"
@.str.4 = [2 x i8] c"a\00"
@.str.5 = [2 x i8] c"w\00"
@reltable.write_conflict_log = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str 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.1 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.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.write_conflict_log to i64)) to i32)]
define i32 @write_conflict_log(i8* nocapture readnone %0, i32 %1, i8* nocapture readnone %2) {
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%6 = add i32 %1, -1
%7 = icmp ult i32 %6, 3
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = sext i32 %6 to i64
%10 = shl i64 %9, 2
%11 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.write_conflict_log to i8*), i64 %10)
%12 = call i32 @strcpy(i8* %5, i8* %11)
br label %13
13: ; preds = %3, %8
%14 = call i64 @access(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 0)
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0)
%17 = call i32* @fopen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %21, label %19
19: ; preds = %13
%20 = call i32 @fclose(i32* %17)
br label %21
21: ; preds = %13, %19
%22 = phi i32 [ 0, %19 ], [ -1, %13 ]
ret i32 %22
}