#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ unlink(char *);
int write_to_smb_tokenfile(char *contents) {
  if (contents == NULL || contents == "") {
    unlink("/opt/etc/.smartsync/smb_tokenfile");
    return 0;
  }
  FILE *fp;
  if ((fp = fopen("/opt/etc/.smartsync/smb_tokenfile", "w")) == NULL) {
    printf("open wd_tokenfile failed!\n");
    return -1;
  }
  fprintf(fp, "%s", contents);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<write_to_smb_tokenfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1178 <write_to_smb_tokenfile+0x28>
lea    0xed0(%rip),%rax
cmp    %rax,-0x10(%rbp)
jne    1190 <write_to_smb_tokenfile+0x40>
lea    0xe81(%rip),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ed <write_to_smb_tokenfile+0x9d>
lea    0xe69(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c9 <write_to_smb_tokenfile+0x79>
lea    0xe6c(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <write_to_smb_tokenfile+0x9d>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe67(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_to_smb_tokenfile>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1198 <write_to_smb_tokenfile+0x48>
mov    %rdi,%rbx
lea    0xeda(%rip),%rax
cmp    %rax,%rdi
je     1198 <write_to_smb_tokenfile+0x48>
lea    0xe91(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ae <write_to_smb_tokenfile+0x5e>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1060 <fputs@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
jmp    11a4 <write_to_smb_tokenfile+0x54>
lea    0xe61(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe6f(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
jmp    11a6 <write_to_smb_tokenfile+0x56>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [34 x i8] c"/opt/etc/.smartsync/smb_tokenfile\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [27 x i8] c"open wd_tokenfile failed!\0A\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @write_to_smb_tokenfile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
br i1 %9, label %10, label %12
10: ; preds = %7, %1
%11 = call i32 @unlink(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %23
12: ; preds = %7
%13 = call i32* @fopen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %13, i32** %4
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %23
17: ; preds = %12
%18 = load i32*, i32** %4
%19 = load i8*, i8** %3
%20 = call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %19)
%21 = load i32*, i32** %4
%22 = call i32 @fclose(i32* %21)
store i32 0, i32* %2
br label %23
23: ; preds = %17, %15, %10
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [34 x i8] c"/opt/etc/.smartsync/smb_tokenfile\00"
@.str.2 = [2 x i8] c"w\00"
@str = [26 x i8] c"open wd_tokenfile failed!\00"
define i32 @write_to_smb_tokenfile(i8* %0) {
%2 = icmp eq i8* %0, null
%3 = icmp eq i8* %0, getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
%4 = or i1 %2, %3
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @unlink(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %15
7: ; preds = %1
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %15
12: ; preds = %7
%13 = tail call i32 @fputs(i8* %0, i32* %8)
%14 = tail call i32 @fclose(i32* %8)
br label %15
15: ; preds = %10, %12, %5
%16 = phi i32 [ 0, %5 ], [ -1, %10 ], [ 0, %12 ]
ret i32 %16
}