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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
void writetestfile() {
  FILE *ofh = fopen("testfile", "w");
  if (!ofh) {
    printf("Can't write test file.\n");
    return;
  }
  unsigned char buffer[] = {
      '4',  '6',  'a', '5',  '\0', '\n', '\n', '\r', '3',  '\r', 't',  '\r',
      '\n', '5',  '9', 'g',  '\r', '\r', '\n', '\n', '4',  '\0', 'f',  '7',
      'g',  'a',  's', '\n', '\n', '\r', 't',  'm',  '\r', '\r', '\n', '3',
      '\0', '\t', '6', '1',  '2',  '\n', '\r', 'U',  'R',  'M',  'T',  '4',
      'I',  'M',  '1', '3',  '3',  '7',  'd',  '0',  '0',  'd'};
  fwrite(buffer, sizeof(char), sizeof(buffer), ofh);
  fclose(ofh);
  return;
}


x86 assembly (clang, -O0):
<writetestfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    0xea1(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    118b <writetestfile+0x3b>
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
jmp    11c0 <writetestfile+0x70>
lea    -0x50(%rbp),%rdi
lea    0xe9a(%rip),%rsi
mov    $0x3a,%edx
call   1050 <memcpy@plt>
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3a,%edx
call   1070 <fwrite@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writetestfile>:
push   %rbx
sub    $0x40,%rsp
lea    0xeb4(%rip),%rdi
lea    0xeb6(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11b1 <writetestfile+0x71>
mov    %rax,%rbx
movups 0xef3(%rip),%xmm0
movups %xmm0,0x2a(%rsp)
movaps 0xedd(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xec1(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xea5(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x3a,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
add    $0x40,%rsp
pop    %rbx
jmp    1040 <fclose@plt>
lea    0xe53(%rip),%rdi
add    $0x40,%rsp
pop    %rbx
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"testfile\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [24 x i8] c"Can't write test file.\0A\00"
@__const.writetestfile.buffer = [58 x i8] c"46a5\00\0A\0A\0D3\0Dt\0D\0A59g\0D\0D\0A\0A4\00f7gas\0A\0A\0Dtm\0D\0D\0A3\00\09612\0A\0DURMT4IM1337d00d"
define void @writetestfile() {
%1 = alloca i32*
%2 = alloca [58 x i8]
%3 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = load i32*, i32** %1
%5 = icmp ne i32* %4, null
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %15
8: ; preds = %0
%9 = bitcast [58 x i8]* %2 to i8*
%10 = getelementptr inbounds [58 x i8], [58 x i8]* %2, i64 0, i64 0
%11 = load i32*, i32** %1
%12 = call i32 @fwrite(i8* %10, i32 1, i32 58, i32* %11)
%13 = load i32*, i32** %1
%14 = call i32 @fclose(i32* %13)
br label %15
15: ; preds = %8, %6
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"testfile\00"
@.str.1 = [2 x i8] c"w\00"
@__const.writetestfile.buffer = [58 x i8] c"46a5\00\0A\0A\0D3\0Dt\0D\0A59g\0D\0D\0A\0A4\00f7gas\0A\0A\0Dtm\0D\0D\0A3\00\09612\0A\0DURMT4IM1337d00d"
@str = [23 x i8] c"Can't write test file.\00"
define void @writetestfile() {
%1 = alloca [58 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %10
6: ; preds = %0
%7 = getelementptr inbounds [58 x i8], [58 x i8]* %1, i64 0, i64 0
%8 = call i32 @fwrite(i8* %7, i32 1, i32 58, i32* %2)
%9 = tail call i32 @fclose(i32* %2)
br label %10
10: ; preds = %6, %4
ret void
}