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

/* Variables and functions */
char *RepMkPathTmp(char *, char *, char *, int);
int S_IRGRP;
int S_IRUSR;
int S_ISGID;
int S_IWGRP;
int S_IWUSR;
int /*<<< orphan*/ _RepCheckString(char *);
int /*<<< orphan*/ _RepCheckType(char *);
scalar_t__ _RepMkDirs(char *);
int /*<<< orphan*/ _RepUpdateTime(char *);
int /*<<< orphan*/ chmod(char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int umask(int);
FILE *RepFwriteTmp(char *Type, char *Filename, char *Ext) {
  FILE *F = NULL;
  char *Fname;
  mode_t Mask;
  if (!_RepCheckType(Type)) {
    fprintf(stderr, "ERROR: Invalid type '%s'\n", Type);
    return (NULL);
  }
  if (!_RepCheckString(Filename)) {
    fprintf(stderr, "ERROR: Invalid filename '%s'\n", Filename);
    return (NULL);
  }
  Fname = RepMkPathTmp(Type, Filename, Ext, 1);
  if (!Fname) {
    fprintf(stderr, "ERROR: Unable to allocate path for '%s/%s'\n", Type,
            Filename);
    return (NULL);
  }
  if (_RepMkDirs(Fname)) {
    free(Fname);
    return (NULL);
  }
  _RepUpdateTime(Fname);
  Mask = umask(0117);
  F = fopen(Fname, "wb");
  if (!F) {
    fprintf(stderr, "ERROR: %s, in %s:%d, failed to open [%s]\n",
            strerror(errno),
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/richardfontana/fossology/refs/heads/"
            "master/devel/libfossrepo/libfossrepo.c",
            628, Fname);
    free(Fname);
    return (NULL);
  }
  chmod(Fname, S_ISGID | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  umask(Mask);
  free(Fname);
  return (F);
}


x86 assembly (clang, -O0):
<RepFwriteTmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <_RepCheckType@plt>
cmp    $0x0,%eax
jne    1206 <RepFwriteTmp+0x56>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1393 <RepFwriteTmp+0x1e3>
mov    -0x18(%rbp),%rdi
call   10b0 <_RepCheckString@plt>
cmp    $0x0,%eax
jne    1240 <RepFwriteTmp+0x90>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1393 <RepFwriteTmp+0x1e3>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0x1,%ecx
call   1080 <RepMkPathTmp@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1291 <RepFwriteTmp+0xe1>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1393 <RepFwriteTmp+0x1e3>
mov    -0x30(%rbp),%rdi
call   10c0 <_RepMkDirs@plt>
cmp    $0x0,%rax
je     12ba <RepFwriteTmp+0x10a>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1393 <RepFwriteTmp+0x1e3>
mov    -0x30(%rbp),%rdi
call   1050 <_RepUpdateTime@plt>
mov    $0x4f,%edi
call   1070 <umask@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xd89(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1344 <RepFwriteTmp+0x194>
mov    0x2cda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
mov    -0x30(%rbp),%r9
lea    0xd4d(%rip),%rsi
lea    0xd70(%rip),%rcx
mov    $0x274,%r8d
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1393 <RepFwriteTmp+0x1e3>
mov    -0x30(%rbp),%rdi
mov    0x2c79(%rip),%rax
mov    (%rax),%esi
mov    0x2c58(%rip),%rax
or     (%rax),%esi
mov    0x2c7f(%rip),%rax
or     (%rax),%esi
mov    0x2c4e(%rip),%rax
or     (%rax),%esi
mov    0x2c75(%rip),%rax
or     (%rax),%esi
call   1090 <chmod@plt>
mov    -0x34(%rbp),%edi
call   1070 <umask@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RepFwriteTmp>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
call   1040 <_RepCheckType@plt>
test   %eax,%eax
je     120b <RepFwriteTmp+0x5b>
mov    %r12,%rdi
call   10b0 <_RepCheckString@plt>
test   %eax,%eax
je     1223 <RepFwriteTmp+0x73>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    $0x1,%ecx
call   1080 <RepMkPathTmp@plt>
test   %rax,%rax
je     124f <RepFwriteTmp+0x9f>
mov    %rax,%r14
mov    %rax,%rdi
call   10c0 <_RepMkDirs@plt>
test   %rax,%rax
je     1271 <RepFwriteTmp+0xc1>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r15d,%r15d
jmp    1240 <RepFwriteTmp+0x90>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
xor    %r15d,%r15d
mov    %rbx,%rdx
jmp    1239 <RepFwriteTmp+0x89>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
lea    0xde7(%rip),%rsi
xor    %r15d,%r15d
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
xor    %r15d,%r15d
mov    %rbx,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1240 <RepFwriteTmp+0x90>
mov    %r14,%rdi
call   1050 <_RepUpdateTime@plt>
mov    $0x4f,%edi
call   1070 <umask@plt>
mov    %eax,%ebx
lea    0xdd8(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12da <RepFwriteTmp+0x12a>
mov    %rax,%r15
mov    0x2d25(%rip),%rax
mov    0x2d06(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d2b(%rip),%rax
or     (%rax),%esi
mov    0x2cfa(%rip),%rax
or     (%rax),%esi
mov    0x2d21(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
call   1090 <chmod@plt>
mov    %ebx,%edi
call   1070 <umask@plt>
jmp    1317 <RepFwriteTmp+0x167>
mov    0x2cef(%rip),%rax
mov    (%rax),%ebx
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd6f(%rip),%rsi
lea    0xd92(%rip),%rcx
xor    %r15d,%r15d
mov    %ebx,%edi
mov    %rax,%rdx
mov    $0x274,%r8d
mov    %r14,%r9
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    1240 <RepFwriteTmp+0x90>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"ERROR: Invalid type '%s'\0A\00"
@.str.1 = [30 x i8] c"ERROR: Invalid filename '%s'\0A\00"
@.str.2 = [44 x i8] c"ERROR: Unable to allocate path for '%s/%s'\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [42 x i8] c"ERROR: %s, in %s:%d, failed to open [%s]\0A\00"
@errno = global i32 0
@.str.5 = [165 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/richardfontana/fossology/refs/heads/master/devel/libfossrepo/libfossrepo.c\00"
@S_ISGID = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
define i32* @RepFwriteTmp(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32* null, i32** %8
%11 = load i8*, i8** %5
%12 = call i32 @_RepCheckType(i8* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %5
%17 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32* null, i32** %4
br label %78
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = call i32 @_RepCheckString(i8* %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %6
%25 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %24)
store i32* null, i32** %4
br label %78
26: ; preds = %18
%27 = load i8*, i8** %5
%28 = load i8*, i8** %6
%29 = load i8*, i8** %7
%30 = call i8* @RepMkPathTmp(i8* %27, i8* %28, i8* %29, i32 1)
store i8* %30, i8** %9
%31 = load i8*, i8** %9
%32 = icmp ne i8* %31, null
br i1 %32, label %38, label %33
33: ; preds = %26
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %5
%36 = load i8*, i8** %6
%37 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %35, i8* %36)
store i32* null, i32** %4
br label %78
38: ; preds = %26
%39 = load i8*, i8** %9
%40 = call i64 @_RepMkDirs(i8* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load i8*, i8** %9
%44 = call i32 @free(i8* %43)
store i32* null, i32** %4
br label %78
45: ; preds = %38
%46 = load i8*, i8** %9
%47 = call i32 @_RepUpdateTime(i8* %46)
%48 = call i32 @umask(i32 79)
store i32 %48, i32* %10
%49 = load i8*, i8** %9
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %50, i32** %8
%51 = load i32*, i32** %8
%52 = icmp ne i32* %51, null
br i1 %52, label %61, label %53
53: ; preds = %45
%54 = load i32, i32* @stderr
%55 = load i32, i32* @errno
%56 = call i8* @strerror(i32 %55)
%57 = load i8*, i8** %9
%58 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* %56, i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str.5, i64 0, i64 0), i32 628, i8* %57)
%59 = load i8*, i8** %9
%60 = call i32 @free(i8* %59)
store i32* null, i32** %4
br label %78
61: ; preds = %45
%62 = load i8*, i8** %9
%63 = load i32, i32* @S_ISGID
%64 = load i32, i32* @S_IRUSR
%65 = or i32 %63, %64
%66 = load i32, i32* @S_IWUSR
%67 = or i32 %65, %66
%68 = load i32, i32* @S_IRGRP
%69 = or i32 %67, %68
%70 = load i32, i32* @S_IWGRP
%71 = or i32 %69, %70
%72 = call i32 @chmod(i8* %62, i32 %71)
%73 = load i32, i32* %10
%74 = call i32 @umask(i32 %73)
%75 = load i8*, i8** %9
%76 = call i32 @free(i8* %75)
%77 = load i32*, i32** %8
store i32* %77, i32** %4
br label %78
78: ; preds = %61, %53, %42, %33, %22, %14
%79 = load i32*, i32** %4
ret i32* %79
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"ERROR: Invalid type '%s'\0A\00"
@.str.1 = [30 x i8] c"ERROR: Invalid filename '%s'\0A\00"
@.str.2 = [44 x i8] c"ERROR: Unable to allocate path for '%s/%s'\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [42 x i8] c"ERROR: %s, in %s:%d, failed to open [%s]\0A\00"
@errno = global i32 0
@.str.5 = [165 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/richardfontana/fossology/refs/heads/master/devel/libfossrepo/libfossrepo.c\00"
@S_ISGID = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
define noalias i32* @RepFwriteTmp(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @_RepCheckType(i8* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %50
9: ; preds = %3
%10 = tail call i32 @_RepCheckString(i8* %1)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %50
15: ; preds = %9
%16 = tail call i8* @RepMkPathTmp(i8* %0, i8* %1, i8* %2, i32 1)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1)
br label %50
21: ; preds = %15
%22 = tail call i64 @_RepMkDirs(i8* %16)
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = tail call i32 @free(i8* %16)
br label %50
26: ; preds = %21
%27 = tail call i32 @_RepUpdateTime(i8* %16)
%28 = tail call i32 @umask(i32 79)
%29 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %37
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = tail call i8* @strerror(i32 %33)
%35 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* %34, i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str.5, i64 0, i64 0), i32 628, i8* %16)
%36 = tail call i32 @free(i8* %16)
br label %50
37: ; preds = %26
%38 = load i32, i32* @S_ISGID
%39 = load i32, i32* @S_IRUSR
%40 = or i32 %39, %38
%41 = load i32, i32* @S_IWUSR
%42 = or i32 %40, %41
%43 = load i32, i32* @S_IRGRP
%44 = or i32 %42, %43
%45 = load i32, i32* @S_IWGRP
%46 = or i32 %44, %45
%47 = tail call i32 @chmod(i8* %16, i32 %46)
%48 = tail call i32 @umask(i32 %28)
%49 = tail call i32 @free(i8* %16)
br label %50
50: ; preds = %37, %31, %24, %18, %12, %6
%51 = phi i32* [ null, %24 ], [ %29, %37 ], [ null, %31 ], [ null, %18 ], [ null, %12 ], [ null, %6 ]
ret i32* %51
}