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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ usageExit(char *);
int main(int argc, char *argv[]) {
  if (argc != 4) {
    usageExit(argv[0]);
  }
  FILE *fp = fopen(argv[1], "w+");
  int len = atoi(argv[2]);
  char c = argv[3][0];
  if (fp == NULL || len <= 0) {
    usageExit(argv[0]);
  }
  int i;
  for (i = 0; i < len; i++) {
    fwrite(&c, 1, 1, fp);
  }
  fflush(fp);
  fclose(fp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     118c <main+0x2c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <usageExit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe65(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    (%rax),%al
mov    %al,-0x1d(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d6 <main+0x76>
cmpl   $0x0,-0x1c(%rbp)
jg     11e2 <main+0x82>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <usageExit@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1217 <main+0xb7>
mov    -0x18(%rbp),%rcx
lea    -0x1d(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1080 <fwrite@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e9 <main+0x89>
mov    -0x18(%rbp),%rdi
call   1040 <fflush@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x4,%edi
je     1177 <main+0x17>
mov    (%r14),%rdi
call   1060 <usageExit@plt>
mov    0x8(%r14),%rdi
lea    0xe7e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    0x10(%r14),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
mov    0x18(%r14),%rax
movsbl (%rax),%ebx
test   %r15,%r15
je     11a5 <main+0x45>
test   %ebp,%ebp
jg     11c0 <main+0x60>
mov    (%r14),%rdi
call   1060 <usageExit@plt>
test   %ebp,%ebp
jle    11cf <main+0x6f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r15,%rsi
call   1040 <fputc@plt>
add    $0xffffffff,%ebp
jne    11c0 <main+0x60>
mov    %r15,%rdi
call   1050 <fflush@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"w+\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 4
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @usageExit(i8* %15)
br label %17
17: ; preds = %12, %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %7
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 3
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
store i8 %30, i8* %8
%31 = load i32*, i32** %6
%32 = icmp eq i32* %31, null
br i1 %32, label %36, label %33
33: ; preds = %17
%34 = load i32, i32* %7
%35 = icmp sle i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %33, %17
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = call i32 @usageExit(i8* %39)
br label %41
41: ; preds = %36, %33
store i32 0, i32* %9
br label %42
42: ; preds = %49, %41
%43 = load i32, i32* %9
%44 = load i32, i32* %7
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %52
46: ; preds = %42
%47 = load i32*, i32** %6
%48 = call i32 @fwrite(i8* %8, i32 1, i32 1, i32* %47)
br label %49
49: ; preds = %46
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
store i32 %51, i32* %9
br label %42
52: ; preds = %42
%53 = load i32*, i32** %6
%54 = call i32 @fflush(i32* %53)
%55 = load i32*, i32** %6
%56 = call i32 @fclose(i32* %55)
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @usageExit(i8* %5)
br label %7
7: ; preds = %4, %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = load i8, i8* %15
%17 = icmp eq i32* %10, null
%18 = icmp slt i32 %13, 1
%19 = select i1 %17, i1 true, i1 %18
br i1 %19, label %20, label %24
20: ; preds = %7
%21 = load i8*, i8** %1
%22 = tail call i32 @usageExit(i8* %21)
%23 = icmp sgt i32 %13, 0
br i1 %23, label %24, label %31
24: ; preds = %7, %20
%25 = sext i8 %16 to i32
br label %26
26: ; preds = %24, %26
%27 = phi i32 [ 0, %24 ], [ %29, %26 ]
%28 = tail call i32 @fputc(i32 %25, i32* %10)
%29 = add nuw nsw i32 %27, 1
%30 = icmp eq i32 %29, %13
br i1 %30, label %31, label %26
31: ; preds = %26, %20
%32 = tail call i32 @fflush(i32* %10)
%33 = tail call i32 @fclose(i32* %10)
ret i32 0
}