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

/* Variables and functions */
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned int, long);
int write_offset(char *filename, ino_t inode, off_t offset) {
  FILE *f;
  if ((f = fopen(filename, "w")) == NULL)
    return errno;
  fprintf(f, "%u %ld\n", (unsigned int)inode, (long int)offset);
  fclose(f);
  if (ferror(f) != 0)
    return errno;
  return 0;
}


x86 assembly (clang, -O0):
<write_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1183 <write_offset+0x43>
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11d1 <write_offset+0x91>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
mov    -0x20(%rbp),%rcx
lea    0xe6a(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11ca <write_offset+0x8a>
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11d1 <write_offset+0x91>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_offset>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     118e <write_offset+0x4e>
mov    %rax,%rbx
lea    0xe9c(%rip),%rsi
mov    %rax,%rdi
mov    %r15d,%edx
mov    %r14,%rcx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1030 <ferror@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     1197 <write_offset+0x57>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@errno = global i32 0
@.str.1 = [8 x i8] c"%u %ld\0A\00"
define i32 @write_offset(i8* %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%9 = load i8*, i8** %5
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %8
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = load i32, i32* @errno
store i32 %13, i32* %4
br label %28
14: ; preds = %3
%15 = load i32*, i32** %8
%16 = load i64, i64* %6
%17 = trunc i64 %16 to i32
%18 = load i64, i64* %7
%19 = call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %17, i64 %18)
%20 = load i32*, i32** %8
%21 = call i32 @fclose(i32* %20)
%22 = load i32*, i32** %8
%23 = call i64 @ferror(i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %14
%26 = load i32, i32* @errno
store i32 %26, i32* %4
br label %28
27: ; preds = %14
store i32 0, i32* %4
br label %28
28: ; preds = %27, %25, %12
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@errno = global i32 0
@.str.1 = [8 x i8] c"%u %ld\0A\00"
define i32 @write_offset(i8* nocapture %0, i64 %1, i64 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = load i32, i32* @errno
br label %16
8: ; preds = %3
%9 = trunc i64 %1 to i32
%10 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %9, i64 %2)
%11 = tail call i32 @fclose(i32* %4)
%12 = tail call i64 @ferror(i32* %4)
%13 = icmp eq i64 %12, 0
%14 = load i32, i32* @errno
%15 = select i1 %13, i32 0, i32 %14
br label %16
16: ; preds = %8, %6
%17 = phi i32 [ %7, %6 ], [ %15, %8 ]
ret i32 %17
}