#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*/ fullname;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ local_mkdir(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int write_notify_file(char *path, int signal_num) {
  FILE *fp;
  char fullname[64];
  memset(fullname, 0, sizeof(fullname));
  local_mkdir("/tmp/notify");
  local_mkdir("/tmp/notify/usb");
  sprintf(fullname, "%s/sambaclient", path);
  fp = fopen(fullname, "w");
  if (NULL == fp) {
    printf("open notify %s file fail\n", fullname);
    return -1;
  }
  fprintf(fp, "%d", signal_num);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<write_notify_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
lea    0xe6a(%rip),%rdi
call   1060 <local_mkdir@plt>
lea    0xe6a(%rip),%rdi
call   1060 <local_mkdir@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe66(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x60(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    11f7 <write_notify_file+0x87>
lea    -0x60(%rbp),%rsi
lea    0xe47(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121a <write_notify_file+0xaa>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe42(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_notify_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %esi,%r14d
mov    %rdi,%rbp
mov    %rsp,%rbx
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
lea    0xe64(%rip),%rdi
call   1060 <local_mkdir@plt>
lea    0xe64(%rip),%rdi
call   1060 <local_mkdir@plt>
lea    0xe68(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1090 <sprintf@plt>
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f2 <write_notify_file+0x82>
mov    %rax,%rbp
lea    0xe6a(%rip),%rsi
mov    %rax,%rdi
mov    %r14d,%edx
call   1070 <fprintf@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
jmp    1207 <write_notify_file+0x97>
lea    0xe34(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/tmp/notify\00"
@.str.1 = [16 x i8] c"/tmp/notify/usb\00"
@.str.2 = [15 x i8] c"%s/sambaclient\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [26 x i8] c"open notify %s file fail\0A\00"
@.str.5 = [3 x i8] c"%d\00"
define i32 @write_notify_file(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca [64 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 64)
%10 = call i32 @local_mkdir(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @local_mkdir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%13 = load i8*, i8** %4
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp eq i32* null, %17
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%21 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %20)
store i32 -1, i32* %3
br label %28
22: ; preds = %2
%23 = load i32*, i32** %6
%24 = load i32, i32* %5
%25 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %24)
%26 = load i32*, i32** %6
%27 = call i32 @fclose(i32* %26)
store i32 0, i32* %3
br label %28
28: ; preds = %22, %19
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [12 x i8] c"/tmp/notify\00"
@.str.1 = [16 x i8] c"/tmp/notify/usb\00"
@.str.2 = [15 x i8] c"%s/sambaclient\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [26 x i8] c"open notify %s file fail\0A\00"
@.str.5 = [3 x i8] c"%d\00"
define i32 @write_notify_file(i8* %0, i32 %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 64)
%6 = call i32 @local_mkdir(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @local_mkdir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%9 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %4)
br label %16
13: ; preds = %2
%14 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %1)
%15 = call i32 @fclose(i32* %9)
br label %16
16: ; preds = %13, %11
%17 = phi i32 [ -1, %11 ], [ 0, %13 ]
ret i32 %17
}