#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 */

/* Variables and functions */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char const *, int, int);
int write(int, char *, int);
int create_file(const char *filename, char *text_content) {
  int c_open;
  int c_write;
  int i;
  c_open = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);
  if (c_open == -1) {
    return (-1);
  }
  if (text_content == NULL)
    text_content = "";
  i = 0;
  while (text_content[i] != '\0') {
    i++;
  }
  c_write = write(c_open, text_content, i);
  if (c_write == -1)
    return (-1);
  close(c_open);
  return (1);
}


x86 assembly (clang, -O0):
<create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ead(%rip),%rax
mov    (%rax),%esi
mov    0x2e9c(%rip),%rax
or     (%rax),%esi
mov    0x2e6b(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1182 <create_file+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <create_file+0xc9>
cmpq   $0x0,-0x18(%rbp)
jne    1198 <create_file+0x68>
lea    0xe6c(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11c2 <create_file+0x92>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119f <create_file+0x6f>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    11ea <create_file+0xba>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <create_file+0xc9>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file>:
push   %rbp
push   %r14
push   %rbx
mov    0x2ebd(%rip),%rcx
mov    0x2eae(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    %rsi,%rbx
mov    0x2e78(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%esi
mov    $0x180,%edx
call   1050 <open@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     11a6 <create_file+0x76>
mov    %eax,%ebp
test   %rbx,%rbx
lea    0xe8b(%rip),%rsi
cmovne %rbx,%rsi
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,(%rsi,%rdx,1)
lea    0x1(%rdx),%rdx
jne    1180 <create_file+0x50>
add    $0xffffffff,%edx
mov    %ebp,%edi
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     11a6 <create_file+0x76>
mov    %ebp,%edi
call   1040 <close@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@.str = [1 x i8] zeroinitializer
define i32 @create_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = load i32, i32* @O_CREAT
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %10, %11
%13 = load i32, i32* @O_WRONLY
%14 = or i32 %12, %13
%15 = call i32 @open(i8* %9, i32 %14, i32 384)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 -1, i32* %3
br label %46
19: ; preds = %2
%20 = load i8*, i8** %5
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %19
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %5
br label %23
23: ; preds = %22, %19
store i32 0, i32* %8
br label %24
24: ; preds = %32, %23
%25 = load i8*, i8** %5
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
br label %24
35: ; preds = %24
%36 = load i32, i32* %6
%37 = load i8*, i8** %5
%38 = load i32, i32* %8
%39 = call i32 @write(i32 %36, i8* %37, i32 %38)
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %43
42: ; preds = %35
store i32 -1, i32* %3
br label %46
43: ; preds = %35
%44 = load i32, i32* %6
%45 = call i32 @close(i32 %44)
store i32 1, i32* %3
br label %46
46: ; preds = %43, %42, %18
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@.str = [1 x i8] zeroinitializer
define i32 @create_file(i8* nocapture %0, i8* %1) {
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_TRUNC
%5 = or i32 %4, %3
%6 = load i32, i32* @O_WRONLY
%7 = or i32 %5, %6
%8 = tail call i32 @open(i8* %0, i32 %7, i32 384)
%9 = icmp eq i32 %8, -1
br i1 %9, label %25, label %10
10: ; preds = %2
%11 = icmp eq i8* %1, null
%12 = select i1 %11, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %1
br label %13
13: ; preds = %13, %10
%14 = phi i64 [ %18, %13 ], [ 0, %10 ]
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
%18 = add nuw i64 %14, 1
br i1 %17, label %19, label %13
19: ; preds = %13
%20 = trunc i64 %14 to i32
%21 = tail call i32 @write(i32 %8, i8* %12, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = tail call i32 @close(i32 %8)
br label %25
25: ; preds = %19, %2, %23
%26 = phi i32 [ 1, %23 ], [ -1, %2 ], [ -1, %19 ]
ret i32 %26
}