freeze(s) char *s;
{
  int fd;
  unsigned int *len;
  len = (unsigned int *)sbrk(0);
  if ((fd = creat(s, 0666)) < 0) {
    perror(s);
    return (1);
  }
  write(fd, &len, sizeof(len));
  write(fd, (char *)0, len);
  close(fd);
  return (0);
}


x86 assembly (clang, -O0):
<freeze>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %edi,%edi
mov    $0x0,%al
call   1050 <sbrk@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1b6,%esi
mov    $0x0,%al
call   1070 <creat@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    119e <freeze+0x4e>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d4 <freeze+0x84>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%esi
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
mov    $0x0,%al
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<freeze>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %r14d,%r14d
xor    %edi,%edi
xor    %eax,%eax
call   1050 <sbrk@plt>
cltq
mov    %rax,0x8(%rsp)
mov    %rbx,%rdi
mov    $0x1b6,%esi
xor    %eax,%eax
call   1070 <creat@plt>
test   %eax,%eax
js     11b1 <freeze+0x61>
mov    %eax,%ebp
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
mov    %eax,%edi
xor    %eax,%eax
call   1030 <write@plt>
mov    0x8(%rsp),%rdx
mov    %ebp,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <write@plt>
mov    %ebp,%edi
xor    %eax,%eax
call   1040 <close@plt>
jmp    11c1 <freeze+0x71>
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <perror@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @freeze(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %3
%6 = call i32 (i32, ...) bitcast (i32 (...)* @sbrk to i32 (i32, ...)*)(i32 0)
%7 = sext i32 %6 to i64
%8 = inttoptr i64 %7 to i32*
store i32* %8, i32** %5
%9 = load i8*, i8** %3
%10 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @creat to i32 (i8*, i32, ...)*)(i8* %9, i32 438)
store i32 %10, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* %13)
store i32 1, i32* %2
br label %23
15: ; preds = %1
%16 = load i32, i32* %4
%17 = call i32 (i32, i32**, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i32**, i64, ...)*)(i32 %16, i32** %5, i64 8)
%18 = load i32, i32* %4
%19 = load i32*, i32** %5
%20 = call i32 (i32, i8*, i32*, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32*, ...)*)(i32 %18, i8* null, i32* %19)
%21 = load i32, i32* %4
%22 = call i32 (i32, ...) bitcast (i32 (...)* @close to i32 (i32, ...)*)(i32 %21)
store i32 0, i32* %2
br label %23
23: ; preds = %15, %12
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
define i32 @freeze(i8* %0) {
%2 = alloca i32*
%3 = bitcast i32** %2 to i8*
%4 = tail call i32 (i32, ...) bitcast (i32 (...)* @sbrk to i32 (i32, ...)*)(i32 0)
%5 = sext i32 %4 to i64
%6 = inttoptr i64 %5 to i32*
store i32* %6, i32** %2
%7 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @creat to i32 (i8*, i32, ...)*)(i8* %0, i32 438)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = tail call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* %0)
br label %16
11: ; preds = %1
%12 = call i32 (i32, i32**, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i32**, i64, ...)*)(i32 %7, i32** %2, i64 8)
%13 = load i32*, i32** %2
%14 = call i32 (i32, i8*, i32*, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32*, ...)*)(i32 %7, i8* null, i32* %13)
%15 = call i32 (i32, ...) bitcast (i32 (...)* @close to i32 (i32, ...)*)(i32 %7)
br label %16
16: ; preds = %11, %9
%17 = phi i32 [ 1, %9 ], [ 0, %11 ]
ret i32 %17
}