#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 errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ printf(char *, char const *);
char *strerror(int);
int main(int argc, const char *argv[]) {
  if (argc != 2) {
    printf("Usage:%s fielname\n", argv[0]);
    return 1;
  }
  FILE *op;
  op = fopen(argv[1], "w");
  if (op == NULL) {
    printf("fopen:%s\n", strerror(errno));
    return errno;
  }
  fclose(op);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     117f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e0 <main+0xa0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe85(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d0 <main+0x90>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11e0 <main+0xa0>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    1167 <main+0x27>
mov    0x8(%rsi),%rdi
lea    0xec2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     117d <main+0x3d>
mov    %rax,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    (%rsi),%rsi
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    0x2e5c(%rip),%rbx
mov    (%rbx),%edi
call   1060 <strerror@plt>
lea    0xe83(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    (%rbx),%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Usage:%s fielname\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [10 x i8] c"fopen:%s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 1, i32* %3
br label %29
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %26
21: ; preds = %14
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @errno
store i32 %25, i32* %3
br label %29
26: ; preds = %14
%27 = load i32*, i32** %6
%28 = call i32 @fclose(i32* %27)
store i32 0, i32* %3
br label %29
29: ; preds = %26, %21, %9
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [19 x i8] c"Usage:%s fielname\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [10 x i8] c"fopen:%s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %19
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %7
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @errno
br label %19
17: ; preds = %7
%18 = tail call i32 @fclose(i32* %10)
br label %19
19: ; preds = %12, %17, %4
%20 = phi i32 [ 1, %4 ], [ %16, %12 ], [ 0, %17 ]
ret i32 %20
}