#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*/ 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) {
    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     1168 <write_to_smb_tokenfile+0x28>
lea    0xec3(%rip),%rax
cmp    %rax,-0x10(%rbp)
jne    1180 <write_to_smb_tokenfile+0x40>
lea    0xe91(%rip),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <write_to_smb_tokenfile+0x91>
lea    0xe79(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ad <write_to_smb_tokenfile+0x6d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d1 <write_to_smb_tokenfile+0x91>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe68(%rip),%rsi
call   1050 <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     1188 <write_to_smb_tokenfile+0x48>
mov    %rdi,%rbx
lea    0xece(%rip),%rax
cmp    %rax,%rdi
je     1188 <write_to_smb_tokenfile+0x48>
lea    0xea1(%rip),%rdi
lea    0xebc(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119e <write_to_smb_tokenfile+0x5e>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <fputs@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    1194 <write_to_smb_tokenfile+0x54>
lea    0xe71(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0xffffffff,%eax
jmp    1196 <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 = [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 %22
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 %16
15: ; preds = %12
store i32 -1, i32* %2
br label %22
16: ; preds = %12
%17 = load i32*, i32** %4
%18 = load i8*, i8** %3
%19 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = load i32*, i32** %4
%21 = call i32 @fclose(i32* %20)
store i32 0, i32* %2
br label %22
22: ; preds = %16, %15, %10
%23 = load i32, i32* %2
ret i32 %23
}

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"
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 %13
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 %13, label %10
10: ; preds = %7
%11 = tail call i32 @fputs(i8* %0, i32* %8)
%12 = tail call i32 @fclose(i32* %8)
br label %13
13: ; preds = %10, %7, %5
%14 = phi i32 [ 0, %5 ], [ 0, %10 ], [ -1, %7 ]
ret i32 %14
}