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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void write_dma_data(void *ptr, int total) {
  FILE *fd;
  time_t tmm;
  char buf[256];
  time(&tmm);
  sprintf(buf, "dma_%ld.cam", tmm);
  if (!(fd = fopen(buf, "w+"))) {
    printf("cant write dma.cam\n");
    return;
  }
  fwrite(ptr, total, 1, fd);
  fclose(fd);
  printf("wrote %d bytes to %s\n", total, buf);
}


x86 assembly (clang, -O0):
<write_dma_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x1c(%rbp),%rdi
call   1050 <time@plt>
lea    -0x120(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe74(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x120(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c5 <write_dma_data+0x65>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11fb <write_dma_data+0x9b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1080 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%esi
lea    -0x120(%rbp),%rdx
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_dma_data>:
push   %rbp
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xc(%rsp),%rdi
call   1060 <time@plt>
mov    0xc(%rsp),%edx
lea    0xe6b(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <sprintf@plt>
lea    0xe63(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ea <write_dma_data+0x7a>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe35(%rip),%rdi
lea    0x10(%rsp),%rdx
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11f6 <write_dma_data+0x86>
lea    0xe34(%rip),%rdi
call   1030 <puts@plt>
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"dma_%ld.cam\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [20 x i8] c"cant write dma.cam\0A\00"
@.str.3 = [22 x i8] c"wrote %d bytes to %s\0A\00"
define void @write_dma_data(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [256 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = call i32 @time(i32* %6)
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%10 = load i32, i32* %6
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %5
%14 = icmp ne i32* %13, null
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %27
17: ; preds = %2
%18 = load i8*, i8** %3
%19 = load i32, i32* %4
%20 = load i32*, i32** %5
%21 = call i32 @fwrite(i8* %18, i32 %19, i32 1, i32* %20)
%22 = load i32*, i32** %5
%23 = call i32 @fclose(i32* %22)
%24 = load i32, i32* %4
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %24, i8* %25)
br label %27
27: ; preds = %17, %15
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"dma_%ld.cam\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.3 = [22 x i8] c"wrote %d bytes to %s\0A\00"
@str = [19 x i8] c"cant write dma.cam\00"
define void @write_dma_data(i8* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = call i32 @time(i32* %3)
%8 = load i32, i32* %3
%9 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %18
14: ; preds = %2
%15 = call i32 @fwrite(i8* %0, i32 %1, i32 1, i32* %10)
%16 = call i32 @fclose(i32* %10)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %1, i8* %6)
br label %18
18: ; preds = %14, %12
ret void
}