#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 */
scalar_t__ EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
scalar_t__ putc(unsigned char, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void serialize_long_long(FILE *out, long long n, long long *fpos,
                         const char *fname) {
  unsigned long long zigzag = (n << 1) ^ (n >> 63);
  while (1) {
    unsigned char b = zigzag & 0x7F;
    if ((zigzag >> 7) != 0) {
      b |= 0x80;
      if (putc(b, out) == EOF) {
        fprintf(stderr, "%s: Write to temporary file failed: %s\n", fname,
                strerror(errno));
        exit(EXIT_FAILURE);
      }
      *fpos += 1;
      zigzag >>= 7;
    } else {
      if (putc(b, out) == EOF) {
        fprintf(stderr, "%s: Write to temporary file failed: %s\n", fname,
                strerror(errno));
        exit(EXIT_FAILURE);
      }
      *fpos += 1;
      break;
    }
  }
}


x86 assembly (clang, -O0):
<serialize_long_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    -0x10(%rbp),%rcx
sar    $0x3f,%rcx
xor    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
and    $0x7f,%rax
mov    %al,-0x29(%rbp)
mov    -0x28(%rbp),%rax
shr    $0x7,%rax
cmp    $0x0,%rax
je     121c <serialize_long_long+0xdc>
movzbl -0x29(%rbp),%eax
or     $0x80,%eax
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1030 <putc@plt>
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%rax
jne    11fd <serialize_long_long+0xbd>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xe16(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
shr    $0x7,%rax
mov    %rax,-0x28(%rbp)
jmp    1294 <serialize_long_long+0x154>
mov    -0x29(%rbp),%al
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1030 <putc@plt>
mov    0x2db6(%rip),%rcx
cmp    (%rcx),%rax
jne    1281 <serialize_long_long+0x141>
mov    0x2d96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xd92(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1299 <serialize_long_long+0x159>
jmp    116f <serialize_long_long+0x2f>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serialize_long_long>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
lea    (%rsi,%rsi,1),%rax
sar    $0x3f,%rbx
xor    %rax,%rbx
cmp    $0x80,%rbx
jae    116e <serialize_long_long+0x2e>
mov    %rbx,%rax
jmp    11ac <serialize_long_long+0x6c>
mov    0x2e73(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%eax
or     $0x80,%al
movzbl %al,%edi
mov    %r12,%rsi
call   1030 <putc@plt>
cmp    0x0(%r13),%rax
je     11d1 <serialize_long_long+0x91>
mov    %rbx,%rax
shr    $0x7,%rax
addq   $0x1,(%r15)
cmp    $0x4000,%rbx
mov    %rax,%rbx
jae    1180 <serialize_long_long+0x40>
movzbl %al,%edi
mov    %r12,%rsi
call   1030 <putc@plt>
mov    0x2e2a(%rip),%rcx
cmp    (%rcx),%rax
je     11d1 <serialize_long_long+0x91>
addq   $0x1,(%r15)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2e00(%rip),%rax
mov    (%rax),%ebx
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe11(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@EOF = global i64 0
@stderr = global i32 0
@.str = [40 x i8] c"%s: Write to temporary file failed: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @serialize_long_long(i32* %0, i64 %1, i64* %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8
store i32* %0, i32** %5
store i64 %1, i64* %6
store i64* %2, i64** %7
store i8* %3, i8** %8
%11 = load i64, i64* %6
%12 = shl i64 %11, 1
%13 = load i64, i64* %6
%14 = ashr i64 %13, 63
%15 = xor i64 %12, %14
store i64 %15, i64* %9
br label %16
16: ; preds = %4, %65
%17 = load i64, i64* %9
%18 = and i64 %17, 127
%19 = trunc i64 %18 to i8
store i8 %19, i8* %10
%20 = load i64, i64* %9
%21 = lshr i64 %20, 7
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %47
23: ; preds = %16
%24 = load i8, i8* %10
%25 = zext i8 %24 to i32
%26 = or i32 %25, 128
%27 = trunc i32 %26 to i8
store i8 %27, i8* %10
%28 = load i8, i8* %10
%29 = load i32*, i32** %5
%30 = call i64 @putc(i8 zeroext %28, i32* %29)
%31 = load i64, i64* @EOF
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %41
33: ; preds = %23
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %8
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %35, i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %23
%42 = load i64*, i64** %7
%43 = load i64, i64* %42
%44 = add nsw i64 %43, 1
store i64 %44, i64* %42
%45 = load i64, i64* %9
%46 = lshr i64 %45, 7
store i64 %46, i64* %9
br label %65
47: ; preds = %16
%48 = load i8, i8* %10
%49 = load i32*, i32** %5
%50 = call i64 @putc(i8 zeroext %48, i32* %49)
%51 = load i64, i64* @EOF
%52 = icmp eq i64 %50, %51
br i1 %52, label %53, label %61
53: ; preds = %47
%54 = load i32, i32* @stderr
%55 = load i8*, i8** %8
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %55, i8* %57)
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %47
%62 = load i64*, i64** %7
%63 = load i64, i64* %62
%64 = add nsw i64 %63, 1
store i64 %64, i64* %62
br label %66
65: ; preds = %41
br label %16
66: ; preds = %61
ret void
}

LLVM IR (-O2):
@EOF = global i64 0
@stderr = global i32 0
@.str = [40 x i8] c"%s: Write to temporary file failed: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @serialize_long_long(i32* nocapture %0, i64 %1, i64* nocapture %2, i8* %3) {
%5 = shl i64 %1, 1
%6 = ashr i64 %1, 63
%7 = xor i64 %5, %6
%8 = icmp ult i64 %7, 128
br i1 %8, label %24, label %9
9: ; preds = %4, %37
%10 = phi i64 [ %11, %37 ], [ %7, %4 ]
%11 = lshr i64 %10, 7
%12 = trunc i64 %10 to i8
%13 = or i8 %12, -128
%14 = tail call i64 @putc(i8 zeroext %13, i32* %0)
%15 = load i64, i64* @EOF
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %37
17: ; preds = %9
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %37, %4
%25 = phi i64 [ %7, %4 ], [ %11, %37 ]
%26 = trunc i64 %25 to i8
%27 = tail call i64 @putc(i8 zeroext %26, i32* %0)
%28 = load i64, i64* @EOF
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %41
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = tail call i8* @strerror(i32 %32)
%34 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = tail call i32 @exit(i32 %35)
unreachable
37: ; preds = %9
%38 = load i64, i64* %2
%39 = add nsw i64 %38, 1
store i64 %39, i64* %2
%40 = icmp ult i64 %10, 16384
br i1 %40, label %24, label %9
41: ; preds = %24
%42 = load i64, i64* %2
%43 = add nsw i64 %42, 1
store i64 %43, i64* %2
ret void
}