#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int getpid();
int /*<<< orphan*/ stderr;
int fwrite_log(FILE *file, const char *msg) {
  if (file == NULL) {
    fprintf(stderr, "fwrite_log: file is NULL\n");
    return 1;
  }
  fprintf(file, "[%d] %s\n", getpid(), msg);
  return 0;
}


x86 assembly (clang, -O0):
<fwrite_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115f <fwrite_log+0x3f>
mov    0x2e9e(%rip),%rax
movslq (%rax),%rdi
lea    0xeb4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    118d <fwrite_log+0x6d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
lea    0xe9b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwrite_log>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     1160 <fwrite_log+0x30>
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xecb(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1185 <fwrite_log+0x55>
mov    0x2e79(%rip),%rax
movslq (%rax),%rcx
lea    0xe8f(%rip),%rdi
mov    $0x19,%esi
mov    $0x1,%edx
call   1050 <fwrite@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"fwrite_log: file is NULL\0A\00"
@.str.1 = [9 x i8] c"[%d] %s\0A\00"
define i32 @fwrite_log(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
%6 = load i32*, i32** %4
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i32*
%12 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %18
13: ; preds = %2
%14 = load i32*, i32** %4
%15 = call i32 (...) @getpid()
%16 = load i8*, i8** %5
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %15, i8* %16)
store i32 0, i32* %3
br label %18
18: ; preds = %13, %8
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"fwrite_log: file is NULL\0A\00"
@.str.1 = [9 x i8] c"[%d] %s\0A\00"
define i32 @fwrite_log(i32* %0, i8* %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i32*
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 25, i64 1, i32* %7)
br label %12
9: ; preds = %2
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %10, i8* %1)
br label %12
12: ; preds = %9, %4
%13 = phi i32 [ 1, %4 ], [ 0, %9 ]
ret i32 %13
}