#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 ssize_t;

/* Variables and functions */
int creat(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strlen(char const *);
int write(int, char const *, int /*<<< orphan*/);
int main(int argc, char const *argv[]) {
  int fd;
  fd = creat("test.txt", 0644);
  if (fd == -1) {
    perror("Ошибка создания файла!");
    exit(-1);
  }
  const char *buf = "Тестовый код для файла";
  ssize_t wd;
  wd = write(fd, buf, strlen(buf));
  if (wd == -1) {
    perror("Ошибка записи");
    exit(-1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    119a <main+0x4a>
lea    0xe7e(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    0xe92(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11ed <main+0x9d>
lea    0xe7f(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
cmp    $0xffffffff,%eax
je     1196 <main+0x46>
mov    %eax,%ebx
lea    0xec0(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     119f <main+0x4f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe6c(%rip),%rdi
jmp    11a6 <main+0x56>
lea    0xeb7(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [42 x i8] c"\D0\9E\D1\88\D0\B8\D0\B1\D0\BA\D0\B0 \D1\81\D0\BE\D0\B7\D0\B4\D0\B0\D0\BD\D0\B8\D1\8F \D1\84\D0\B0\D0\B9\D0\BB\D0\B0!\00"
@.str.2 = [42 x i8] c"\D0\A2\D0\B5\D1\81\D1\82\D0\BE\D0\B2\D1\8B\D0\B9 \D0\BA\D0\BE\D0\B4 \D0\B4\D0\BB\D1\8F \D1\84\D0\B0\D0\B9\D0\BB\D0\B0\00"
@.str.3 = [26 x i8] c"\D0\9E\D1\88\D0\B8\D0\B1\D0\BA\D0\B0 \D0\B7\D0\B0\D0\BF\D0\B8\D1\81\D0\B8\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @creat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 420)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %2
store i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8** %7
%16 = load i32, i32* %6
%17 = load i8*, i8** %7
%18 = load i8*, i8** %7
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @write(i32 %16, i8* %17, i32 %19)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [42 x i8] c"\D0\9E\D1\88\D0\B8\D0\B1\D0\BA\D0\B0 \D1\81\D0\BE\D0\B7\D0\B4\D0\B0\D0\BD\D0\B8\D1\8F \D1\84\D0\B0\D0\B9\D0\BB\D0\B0!\00"
@.str.2 = [42 x i8] c"\D0\A2\D0\B5\D1\81\D1\82\D0\BE\D0\B2\D1\8B\D0\B9 \D0\BA\D0\BE\D0\B4 \D0\B4\D0\BB\D1\8F \D1\84\D0\B0\D0\B9\D0\BB\D0\B0\00"
@.str.3 = [26 x i8] c"\D0\9E\D1\88\D0\B8\D0\B1\D0\BA\D0\B0 \D0\B7\D0\B0\D0\BF\D0\B8\D1\81\D0\B8\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @creat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 420)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %8
ret i32 0
}