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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
scalar_t__ strtol(char *, char **, int);
int create_file(char *filename, char *argv[], int len) {
  FILE *f = fopen(filename, "wb");
  int i = 0;
  int n = 0;
  if (!f) {
    return -1;
  }
  for (i = 0; i < len; i++) {
    n = (int)strtol(argv[i], (char **)0, 10);
    fwrite(&n, sizeof(n), 1, f);
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118c <create_file+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <create_file+0xb1>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e1 <create_file+0xa1>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rcx
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1193 <create_file+0x53>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
lea    0xea8(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11be <create_file+0x7e>
mov    %rax,%r12
test   %ebp,%ebp
jle    11b2 <create_file+0x72>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xc(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14,%rbx,8),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,0xc(%rsp)
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1060 <fwrite@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <create_file+0x40>
mov    %r12,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11c3 <create_file+0x83>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
define i32 @create_file(i8* %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
store i32 0, i32* %9
store i32 0, i32* %10
%13 = load i32*, i32** %8
%14 = icmp ne i32* %13, null
br i1 %14, label %16, label %15
15: ; preds = %3
store i32 -1, i32* %4
br label %37
16: ; preds = %3
store i32 0, i32* %9
br label %17
17: ; preds = %31, %16
%18 = load i32, i32* %9
%19 = load i32, i32* %7
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %34
21: ; preds = %17
%22 = load i8**, i8*** %6
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i64 @strtol(i8* %26, i8** null, i32 10)
%28 = trunc i64 %27 to i32
store i32 %28, i32* %10
%29 = load i32*, i32** %8
%30 = call i32 @fwrite(i32* %10, i32 4, i32 1, i32* %29)
br label %31
31: ; preds = %21
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
br label %17
34: ; preds = %17
%35 = load i32*, i32** %8
%36 = call i32 @fclose(i32* %35)
store i32 0, i32* %4
br label %37
37: ; preds = %34, %15
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
define i32 @create_file(i8* nocapture %0, i8** nocapture %1, i32 %2) {
%4 = alloca i32
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32* %5, null
br i1 %7, label %23, label %8
8: ; preds = %3
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %21
10: ; preds = %8
%11 = zext i32 %2 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %19, %12 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = tail call i64 @strtol(i8* nocapture %15, i8** null, i32 10)
%17 = trunc i64 %16 to i32
store i32 %17, i32* %4
%18 = call i32 @fwrite(i32* %4, i32 4, i32 1, i32* %5)
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, %11
br i1 %20, label %21, label %12
21: ; preds = %12, %8
%22 = tail call i32 @fclose(i32* %5)
br label %23
23: ; preds = %3, %21
%24 = phi i32 [ 0, %21 ], [ -1, %3 ]
ret i32 %24
}