#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 S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int creat(char const *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int create_file2(const char *pathname, char *str_table[]) {
  int fd;
  int i;
  char *str;
  fd = creat(pathname, S_IRUSR | S_IWUSR);
  if (fd < 0) {
    return fd;
  }
  for (i = 0; str_table[i] != NULL; i++) {
    str = str_table[i];
    write(fd, str, strlen(str));
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<create_file2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
mov    0x2e84(%rip),%rax
or     (%rax),%esi
call   1060 <creat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1183 <create_file2+0x43>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ef <create_file2+0xaf>
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11e0 <create_file2+0xa0>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    118a <create_file2+0x4a>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file2>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    0x2e8a(%rip),%rax
mov    0x2e93(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1060 <creat@plt>
mov    %eax,%r14d
test   %eax,%eax
js     11ac <create_file2+0x6c>
mov    (%rbx),%rbp
test   %rbp,%rbp
je     11a1 <create_file2+0x61>
add    $0x8,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    (%rbx),%rbp
add    $0x8,%rbx
test   %rbp,%rbp
jne    1180 <create_file2+0x40>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @create_file2(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
%9 = load i8*, i8** %4
%10 = load i32, i32* @S_IRUSR
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %10, %11
%13 = call i32 @creat(i8* %9, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = load i32, i32* %6
store i32 %17, i32* %3
br label %43
18: ; preds = %2
store i32 0, i32* %7
br label %19
19: ; preds = %37, %18
%20 = load i8**, i8*** %5
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %40
26: ; preds = %19
%27 = load i8**, i8*** %5
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
store i8* %31, i8** %8
%32 = load i32, i32* %6
%33 = load i8*, i8** %8
%34 = load i8*, i8** %8
%35 = call i32 @strlen(i8* %34)
%36 = call i32 @write(i32 %32, i8* %33, i32 %35)
br label %37
37: ; preds = %26
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %19
40: ; preds = %19
%41 = load i32, i32* %6
%42 = call i32 @close(i32 %41)
store i32 0, i32* %3
br label %43
43: ; preds = %40, %16
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @create_file2(i8* %0, i8** nocapture %1) {
%3 = load i32, i32* @S_IRUSR
%4 = load i32, i32* @S_IWUSR
%5 = or i32 %4, %3
%6 = tail call i32 @creat(i8* %0, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = icmp eq i8* %9, null
br i1 %10, label %20, label %11
11: ; preds = %8, %11
%12 = phi i64 [ %16, %11 ], [ 0, %8 ]
%13 = phi i8* [ %18, %11 ], [ %9, %8 ]
%14 = tail call i32 @strlen(i8* %13)
%15 = tail call i32 @write(i32 %6, i8* %13, i32 %14)
%16 = add nuw i64 %12, 1
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %11
20: ; preds = %11, %8
%21 = tail call i32 @close(i32 %6)
br label %22
22: ; preds = %2, %20
%23 = phi i32 [ 0, %20 ], [ %6, %2 ]
ret i32 %23
}