#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 S_IRUSR;
int S_IWUSR;
int close(int);
int my_strlen(char *);
int open(char *, int, int);
int write(int, char *, int);
int creat_file(char **tab3) {
  int fd;
  int i;
  i = 0;
  if ((fd = open(" ", O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR)) == -1)
    return (1);
  if (tab3[0] == NULL)
    return (1);
  while (tab3[i]) {
    if ((write(fd, tab3[i], my_strlen(tab3[i]))) == -1)
      return (1);
    if ((write(fd, "\n", 1)) == -1)
      return (1);
    i++;
  }
  if (close(fd) == -1)
    return (1);
  return (0);
}


x86 assembly (clang, -O0):
<creat_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
mov    0x2e55(%rip),%rax
or     (%rax),%esi
mov    0x2e84(%rip),%rax
or     (%rax),%esi
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
mov    0x2e5a(%rip),%rax
or     (%rax),%edx
lea    0xe79(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11a4 <creat_file+0x64>
movl   $0x1,-0x4(%rbp)
jmp    127b <creat_file+0x13b>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11be <creat_file+0x7e>
movl   $0x1,-0x4(%rbp)
jmp    127b <creat_file+0x13b>
jmp    11c3 <creat_file+0x83>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1257 <creat_file+0x117>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <my_strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1220 <creat_file+0xe0>
movl   $0x1,-0x4(%rbp)
jmp    127b <creat_file+0x13b>
mov    -0x14(%rbp),%edi
lea    0xdd8(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1249 <creat_file+0x109>
movl   $0x1,-0x4(%rbp)
jmp    127b <creat_file+0x13b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c3 <creat_file+0x83>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    1274 <creat_file+0x134>
movl   $0x1,-0x4(%rbp)
jmp    127b <creat_file+0x13b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<creat_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2ea7(%rip),%rax
mov    0x2e60(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e8d(%rip),%rax
or     (%rax),%esi
mov    0x2e5c(%rip),%rax
mov    0x2e65(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe82(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11f3 <creat_file+0xb3>
mov    (%rbx),%rbp
test   %rbp,%rbp
je     11f3 <creat_file+0xb3>
mov    %eax,%r15d
add    $0x8,%rbx
lea    0xe64(%rip),%r14
xchg   %ax,%ax
mov    %rbp,%rdi
call   1030 <my_strlen@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    $0x1,%ebp
cmp    $0xffffffff,%eax
je     11f8 <creat_file+0xb8>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     11f8 <creat_file+0xb8>
mov    (%rbx),%rbp
add    $0x8,%rbx
test   %rbp,%rbp
jne    11a0 <creat_file+0x60>
mov    %r15d,%edi
call   1050 <close@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
sete   %bpl
jmp    11f8 <creat_file+0xb8>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @creat_file(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
store i8** %0, i8*** %3
store i32 0, i32* %5
%6 = load i32, i32* @O_CREAT
%7 = load i32, i32* @O_WRONLY
%8 = or i32 %6, %7
%9 = load i32, i32* @O_TRUNC
%10 = or i32 %8, %9
%11 = load i32, i32* @S_IRUSR
%12 = load i32, i32* @S_IWUSR
%13 = or i32 %11, %12
%14 = call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %13)
store i32 %14, i32* %4
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %1
store i32 1, i32* %2
br label %61
17: ; preds = %1
%18 = load i8**, i8*** %3
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 1, i32* %2
br label %61
23: ; preds = %17
br label %24
24: ; preds = %52, %23
%25 = load i8**, i8*** %3
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %55
31: ; preds = %24
%32 = load i32, i32* %4
%33 = load i8**, i8*** %3
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = load i8**, i8*** %3
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i32 @my_strlen(i8* %42)
%44 = call i32 @write(i32 %32, i8* %37, i32 %43)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %47
46: ; preds = %31
store i32 1, i32* %2
br label %61
47: ; preds = %31
%48 = load i32, i32* %4
%49 = call i32 @write(i32 %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %52
51: ; preds = %47
store i32 1, i32* %2
br label %61
52: ; preds = %47
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %24
55: ; preds = %24
%56 = load i32, i32* %4
%57 = call i32 @close(i32 %56)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %60
59: ; preds = %55
store i32 1, i32* %2
br label %61
60: ; preds = %55
store i32 0, i32* %2
br label %61
61: ; preds = %60, %59, %51, %46, %22, %16
%62 = load i32, i32* %2
ret i32 %62
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @creat_file(i8** nocapture %0) {
%2 = load i32, i32* @O_CREAT
%3 = load i32, i32* @O_WRONLY
%4 = or i32 %3, %2
%5 = load i32, i32* @O_TRUNC
%6 = or i32 %4, %5
%7 = load i32, i32* @S_IRUSR
%8 = load i32, i32* @S_IWUSR
%9 = or i32 %8, %7
%10 = tail call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %33, label %12
12: ; preds = %1
%13 = load i8*, i8** %0
%14 = icmp eq i8* %13, null
br i1 %14, label %33, label %19
15: ; preds = %25
%16 = getelementptr inbounds i8*, i8** %0, i64 %28
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %29, label %19
19: ; preds = %12, %15
%20 = phi i64 [ %28, %15 ], [ 0, %12 ]
%21 = phi i8* [ %17, %15 ], [ %13, %12 ]
%22 = tail call i32 @my_strlen(i8* %21)
%23 = tail call i32 @write(i32 %10, i8* %21, i32 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %33, label %25
25: ; preds = %19
%26 = tail call i32 @write(i32 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%27 = icmp eq i32 %26, -1
%28 = add nuw i64 %20, 1
br i1 %27, label %33, label %15
29: ; preds = %15
%30 = tail call i32 @close(i32 %10)
%31 = icmp eq i32 %30, -1
%32 = zext i1 %31 to i32
br label %33
33: ; preds = %25, %19, %29, %12, %1
%34 = phi i32 [ 1, %1 ], [ 1, %12 ], [ %32, %29 ], [ 1, %19 ], [ 1, %25 ]
ret i32 %34
}