#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 */

/* Variables and functions */
int EIO;
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int errno;
scalar_t__ fsync(int);
int /*<<< orphan*/ logError(char *, int, char const *, int, char *);
int open(char const *, int, int);
char *strerror(int);
int const write(int, char const *, int const);
int writeToFile(const char *filename, const char *buff, const int file_size) {
  int fd;
  int result;
  fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
  if (fd < 0) {
    result = errno != 0 ? errno : EIO;
    logError("file: "
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/"
             "fastdfs-5.01/common/shared_func.c"
             ", line: %d, "
             "open file %s fail, "
             "errno: %d, error info: %s",
             1113, filename, result,
             (strerror(result) != NULL ? strerror(result) : "Unkown error"));
    return result;
  }
  if (write(fd, buff, file_size) != file_size) {
    result = errno != 0 ? errno : EIO;
    logError("file: "
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/"
             "fastdfs-5.01/common/shared_func.c"
             ", line: %d, "
             "write file %s fail, "
             "errno: %d, error info: %s",
             1124, filename, result,
             (strerror(result) != NULL ? strerror(result) : "Unkown error"));
    close(fd);
    return result;
  }
  if (fsync(fd) != 0) {
    result = errno != 0 ? errno : EIO;
    logError("file: "
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/"
             "fastdfs-5.01/common/shared_func.c"
             ", line: %d, "
             "fsync file \"%s\" fail, "
             "errno: %d, error info: %s",
             1137, filename, result,
             (strerror(result) != NULL ? strerror(result) : "Unkown error"));
    close(fd);
    return result;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<writeToFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
mov    0x2e71(%rip),%rax
or     (%rax),%esi
mov    0x2e60(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1244 <writeToFile+0xe4>
mov    0x2e18(%rip),%rax
cmpl   $0x0,(%rax)
je     11ca <writeToFile+0x6a>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    11d6 <writeToFile+0x76>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%edi
call   1080 <strerror@plt>
cmp    $0x0,%rax
je     120d <writeToFile+0xad>
mov    -0x24(%rbp),%edi
call   1080 <strerror@plt>
mov    %rax,-0x40(%rbp)
jmp    121d <writeToFile+0xbd>
lea    0xec9(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    121d <writeToFile+0xbd>
mov    -0x2c(%rbp),%ecx
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%r8
lea    0xdd1(%rip),%rdi
mov    $0x459,%esi
call   1040 <logError@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13c3 <writeToFile+0x263>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
cmp    -0x1c(%rbp),%eax
je     12ff <writeToFile+0x19f>
mov    0x2d65(%rip),%rax
cmpl   $0x0,(%rax)
je     127d <writeToFile+0x11d>
mov    0x2d55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    1289 <writeToFile+0x129>
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x24(%rbp),%edi
call   1080 <strerror@plt>
cmp    $0x0,%rax
je     12c0 <writeToFile+0x160>
mov    -0x24(%rbp),%edi
call   1080 <strerror@plt>
mov    %rax,-0x58(%rbp)
jmp    12d0 <writeToFile+0x170>
lea    0xe16(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    12d0 <writeToFile+0x170>
mov    -0x48(%rbp),%ecx
mov    -0x50(%rbp),%rdx
mov    -0x58(%rbp),%r8
lea    0xe08(%rip),%rdi
mov    $0x464,%esi
call   1040 <logError@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13c3 <writeToFile+0x263>
mov    -0x20(%rbp),%edi
call   1060 <fsync@plt>
cmp    $0x0,%rax
je     13b4 <writeToFile+0x254>
mov    0x2cb0(%rip),%rax
cmpl   $0x0,(%rax)
je     1332 <writeToFile+0x1d2>
mov    0x2ca0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    133e <writeToFile+0x1de>
mov    0x2c97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x24(%rbp),%edi
call   1080 <strerror@plt>
cmp    $0x0,%rax
je     1375 <writeToFile+0x215>
mov    -0x24(%rbp),%edi
call   1080 <strerror@plt>
mov    %rax,-0x70(%rbp)
jmp    1385 <writeToFile+0x225>
lea    0xd61(%rip),%rax
mov    %rax,-0x70(%rbp)
jmp    1385 <writeToFile+0x225>
mov    -0x60(%rbp),%ecx
mov    -0x68(%rbp),%rdx
mov    -0x70(%rbp),%r8
lea    0xe31(%rip),%rdi
mov    $0x471,%esi
call   1040 <logError@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13c3 <writeToFile+0x263>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeToFile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e4a(%rip),%rcx
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e68(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%esi
mov    $0x1a4,%edx
call   1070 <open@plt>
test   %eax,%eax
js     11f3 <writeToFile+0x93>
mov    %eax,%r15d
mov    %eax,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
cmp    %ebp,%eax
jne    1221 <writeToFile+0xc1>
mov    %r15d,%edi
call   1060 <fsync@plt>
test   %rax,%rax
je     126e <writeToFile+0x10e>
mov    0x2e03(%rip),%rax
mov    (%rax),%ebp
test   %ebp,%ebp
jne    11d4 <writeToFile+0x74>
mov    0x2dfe(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
test   %rax,%rax
je     128f <writeToFile+0x12f>
mov    %ebp,%edi
call   1080 <strerror@plt>
mov    %rax,%r8
jmp    1296 <writeToFile+0x136>
mov    0x2dce(%rip),%rax
mov    (%rax),%ebp
test   %ebp,%ebp
jne    1209 <writeToFile+0xa9>
mov    0x2dc9(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
test   %rax,%rax
je     124f <writeToFile+0xef>
mov    %ebp,%edi
call   1080 <strerror@plt>
mov    %rax,%r8
jmp    1256 <writeToFile+0xf6>
mov    0x2da0(%rip),%rax
mov    (%rax),%ebp
test   %ebp,%ebp
jne    1237 <writeToFile+0xd7>
mov    0x2d9b(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
test   %rax,%rax
je     127a <writeToFile+0x11a>
mov    %ebp,%edi
call   1080 <strerror@plt>
mov    %rax,%r8
jmp    1281 <writeToFile+0x121>
lea    0xe87(%rip),%r8
lea    0xda3(%rip),%rdi
mov    $0x459,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1040 <logError@plt>
jmp    12b4 <writeToFile+0x154>
mov    %r15d,%edi
call   1050 <close@plt>
xor    %ebp,%ebp
jmp    12b4 <writeToFile+0x154>
lea    0xe5c(%rip),%r8
lea    0xe62(%rip),%rdi
mov    $0x464,%esi
jmp    12a2 <writeToFile+0x142>
lea    0xe47(%rip),%r8
lea    0xf2b(%rip),%rdi
mov    $0x471,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1040 <logError@plt>
mov    %r15d,%edi
call   1050 <close@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@errno = global i32 0
@EIO = global i32 0
@.str = [221 x i8] c"file: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/fastdfs-5.01/common/shared_func.c, line: %d, open file %s fail, errno: %d, error info: %s\00"
@.str.1 = [13 x i8] c"Unkown error\00"
@.str.2 = [222 x i8] c"file: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/fastdfs-5.01/common/shared_func.c, line: %d, write file %s fail, errno: %d, error info: %s\00"
@.str.3 = [224 x i8] c"file: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/fastdfs-5.01/common/shared_func.c, line: %d, fsync file \22%s\22 fail, errno: %d, error info: %s\00"
define i32 @writeToFile(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = load i32, i32* @O_WRONLY
%12 = load i32, i32* @O_CREAT
%13 = or i32 %11, %12
%14 = load i32, i32* @O_TRUNC
%15 = or i32 %13, %14
%16 = call i32 @open(i8* %10, i32 %15, i32 420)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %41
19: ; preds = %3
%20 = load i32, i32* @errno
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = load i32, i32* @errno
br label %26
24: ; preds = %19
%25 = load i32, i32* @EIO
br label %26
26: ; preds = %24, %22
%27 = phi i32 [ %23, %22 ], [ %25, %24 ]
store i32 %27, i32* %9
%28 = load i8*, i8** %5
%29 = load i32, i32* %9
%30 = load i32, i32* %9
%31 = call i8* @strerror(i32 %30)
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %36
33: ; preds = %26
%34 = load i32, i32* %9
%35 = call i8* @strerror(i32 %34)
br label %37
36: ; preds = %26
br label %37
37: ; preds = %36, %33
%38 = phi i8* [ %35, %33 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %36 ]
%39 = call i32 @logError(i8* getelementptr inbounds ([221 x i8], [221 x i8]* @.str, i64 0, i64 0), i32 1113, i8* %28, i32 %29, i8* %38)
%40 = load i32, i32* %9
store i32 %40, i32* %4
br label %103
41: ; preds = %3
%42 = load i32, i32* %8
%43 = load i8*, i8** %6
%44 = load i32, i32* %7
%45 = call i32 @write(i32 %42, i8* %43, i32 %44)
%46 = load i32, i32* %7
%47 = icmp ne i32 %45, %46
br i1 %47, label %48, label %72
48: ; preds = %41
%49 = load i32, i32* @errno
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = load i32, i32* @errno
br label %55
53: ; preds = %48
%54 = load i32, i32* @EIO
br label %55
55: ; preds = %53, %51
%56 = phi i32 [ %52, %51 ], [ %54, %53 ]
store i32 %56, i32* %9
%57 = load i8*, i8** %5
%58 = load i32, i32* %9
%59 = load i32, i32* %9
%60 = call i8* @strerror(i32 %59)
%61 = icmp ne i8* %60, null
br i1 %61, label %62, label %65
62: ; preds = %55
%63 = load i32, i32* %9
%64 = call i8* @strerror(i32 %63)
br label %66
65: ; preds = %55
br label %66
66: ; preds = %65, %62
%67 = phi i8* [ %64, %62 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %65 ]
%68 = call i32 @logError(i8* getelementptr inbounds ([222 x i8], [222 x i8]* @.str.2, i64 0, i64 0), i32 1124, i8* %57, i32 %58, i8* %67)
%69 = load i32, i32* %8
%70 = call i32 @close(i32 %69)
%71 = load i32, i32* %9
store i32 %71, i32* %4
br label %103
72: ; preds = %41
%73 = load i32, i32* %8
%74 = call i64 @fsync(i32 %73)
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %100
76: ; preds = %72
%77 = load i32, i32* @errno
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %76
%80 = load i32, i32* @errno
br label %83
81: ; preds = %76
%82 = load i32, i32* @EIO
br label %83
83: ; preds = %81, %79
%84 = phi i32 [ %80, %79 ], [ %82, %81 ]
store i32 %84, i32* %9
%85 = load i8*, i8** %5
%86 = load i32, i32* %9
%87 = load i32, i32* %9
%88 = call i8* @strerror(i32 %87)
%89 = icmp ne i8* %88, null
br i1 %89, label %90, label %93
90: ; preds = %83
%91 = load i32, i32* %9
%92 = call i8* @strerror(i32 %91)
br label %94
93: ; preds = %83
br label %94
94: ; preds = %93, %90
%95 = phi i8* [ %92, %90 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %93 ]
%96 = call i32 @logError(i8* getelementptr inbounds ([224 x i8], [224 x i8]* @.str.3, i64 0, i64 0), i32 1137, i8* %85, i32 %86, i8* %95)
%97 = load i32, i32* %8
%98 = call i32 @close(i32 %97)
%99 = load i32, i32* %9
store i32 %99, i32* %4
br label %103
100: ; preds = %72
%101 = load i32, i32* %8
%102 = call i32 @close(i32 %101)
store i32 0, i32* %4
br label %103
103: ; preds = %100, %94, %66, %37
%104 = load i32, i32* %4
ret i32 %104
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@errno = global i32 0
@EIO = global i32 0
@.str = [221 x i8] c"file: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/fastdfs-5.01/common/shared_func.c, line: %d, open file %s fail, errno: %d, error info: %s\00"
@.str.1 = [13 x i8] c"Unkown error\00"
@.str.2 = [222 x i8] c"file: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/fastdfs-5.01/common/shared_func.c, line: %d, write file %s fail, errno: %d, error info: %s\00"
@.str.3 = [224 x i8] c"file: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fatedier/studies/refs/heads/master/fastdfs-5.01/common/shared_func.c, line: %d, fsync file \22%s\22 fail, errno: %d, error info: %s\00"
define i32 @writeToFile(i8* %0, i8* nocapture %1, i32 %2) {
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = load i32, i32* @O_TRUNC
%8 = or i32 %6, %7
%9 = tail call i32 @open(i8* %0, i32 %8, i32 420)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %3
%12 = load i32, i32* @errno
%13 = icmp eq i32 %12, 0
%14 = load i32, i32* @EIO
%15 = select i1 %13, i32 %14, i32 %12
%16 = tail call i8* @strerror(i32 %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %20, label %18
18: ; preds = %11
%19 = tail call i8* @strerror(i32 %15)
br label %20
20: ; preds = %11, %18
%21 = phi i8* [ %19, %18 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %11 ]
%22 = tail call i32 @logError(i8* getelementptr inbounds ([221 x i8], [221 x i8]* @.str, i64 0, i64 0), i32 1113, i8* %0, i32 %15, i8* %21)
br label %57
23: ; preds = %3
%24 = tail call i32 @write(i32 %9, i8* %1, i32 %2)
%25 = icmp eq i32 %24, %2
br i1 %25, label %39, label %26
26: ; preds = %23
%27 = load i32, i32* @errno
%28 = icmp eq i32 %27, 0
%29 = load i32, i32* @EIO
%30 = select i1 %28, i32 %29, i32 %27
%31 = tail call i8* @strerror(i32 %30)
%32 = icmp eq i8* %31, null
br i1 %32, label %35, label %33
33: ; preds = %26
%34 = tail call i8* @strerror(i32 %30)
br label %35
35: ; preds = %26, %33
%36 = phi i8* [ %34, %33 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %26 ]
%37 = tail call i32 @logError(i8* getelementptr inbounds ([222 x i8], [222 x i8]* @.str.2, i64 0, i64 0), i32 1124, i8* %0, i32 %30, i8* %36)
%38 = tail call i32 @close(i32 %9)
br label %57
39: ; preds = %23
%40 = tail call i64 @fsync(i32 %9)
%41 = icmp eq i64 %40, 0
br i1 %41, label %55, label %42
42: ; preds = %39
%43 = load i32, i32* @errno
%44 = icmp eq i32 %43, 0
%45 = load i32, i32* @EIO
%46 = select i1 %44, i32 %45, i32 %43
%47 = tail call i8* @strerror(i32 %46)
%48 = icmp eq i8* %47, null
br i1 %48, label %51, label %49
49: ; preds = %42
%50 = tail call i8* @strerror(i32 %46)
br label %51
51: ; preds = %42, %49
%52 = phi i8* [ %50, %49 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %42 ]
%53 = tail call i32 @logError(i8* getelementptr inbounds ([224 x i8], [224 x i8]* @.str.3, i64 0, i64 0), i32 1137, i8* %0, i32 %46, i8* %52)
%54 = tail call i32 @close(i32 %9)
br label %57
55: ; preds = %39
%56 = tail call i32 @close(i32 %9)
br label %57
57: ; preds = %55, %51, %35, %20
%58 = phi i32 [ %15, %20 ], [ %30, %35 ], [ %46, %51 ], [ 0, %55 ]
ret i32 %58
}