#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, long);
scalar_t__ getpid();
int /*<<< orphan*/ perror(char *);
void writepid(char *tmpfile) {
  FILE *f;
  f = fopen(tmpfile, "w");
  if (f == NULL) {
    perror("colorize (fopen)");
    exit(EXIT_FAILURE);
  }
  fprintf(f, "%ld\n", (long)getpid());
  if (fclose(f) != 0) {
    perror("colorize (fclose)");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<writepid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a5 <writepid+0x45>
lea    0xe70(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x18(%rbp),%rdi
mov    %rax,%rdx
lea    0xe51(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     11f4 <writepid+0x94>
lea    0xe37(%rip),%rdi
call   1070 <perror@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writepid>:
push   %rbx
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119d <writepid+0x3d>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe90(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
jne    11a6 <writepid+0x46>
pop    %rbx
ret
lea    0xe5e(%rip),%rdi
jmp    11ad <writepid+0x4d>
lea    0xe6b(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [17 x i8] c"colorize (fopen)\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"%ld\0A\00"
@.str.3 = [18 x i8] c"colorize (fclose)\00"
define void @writepid(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
%13 = load i32*, i32** %3
%14 = call i64 (...) @getpid()
%15 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %14)
%16 = load i32*, i32** %3
%17 = call i64 @fclose(i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %12
%20 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [17 x i8] c"colorize (fopen)\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"%ld\0A\00"
@.str.3 = [18 x i8] c"colorize (fclose)\00"
define void @writepid(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %1
%9 = tail call i64 (...) @getpid()
%10 = tail call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %9)
%11 = tail call i64 @fclose(i32* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %8
ret void
}