#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_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  int fd;
  fd = open(argv[1], O_CREAT | O_RDWR, 0640);
  dup2(fd, 1);
  dup2(fd, 2);
  close(fd);
  printf("HOLA MUNDO\n");
  perror("ERROR.");
  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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
mov    0x2e62(%rip),%rax
or     (%rax),%esi
mov    $0x1a0,%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    -0x14(%rbp),%edi
mov    $0x2,%esi
call   1030 <dup2@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
lea    0xe4a(%rip),%rdi
call   1040 <printf@plt>
lea    0xe4a(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x8(%rsi),%rdi
mov    0x2e9c(%rip),%rax
mov    0x2e7d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1a0,%edx
call   1060 <open@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
mov    %ebx,%edi
mov    $0x2,%esi
call   1040 <dup2@plt>
mov    %ebx,%edi
call   1050 <close@plt>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe5b(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str = [12 x i8] c"HOLA MUNDO\0A\00"
@.str.1 = [7 x i8] c"ERROR.\00"
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 i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_CREAT
%11 = load i32, i32* @O_RDWR
%12 = or i32 %10, %11
%13 = call i32 @open(i8* %9, i32 %12, i32 416)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = call i32 @dup2(i32 %14, i32 1)
%16 = load i32, i32* %6
%17 = call i32 @dup2(i32 %16, i32 2)
%18 = load i32, i32* %6
%19 = call i32 @close(i32 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.1 = [7 x i8] c"ERROR.\00"
@str = [11 x i8] c"HOLA MUNDO\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i32, i32* @O_CREAT
%6 = load i32, i32* @O_RDWR
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* %4, i32 %7, i32 416)
%9 = tail call i32 @dup2(i32 %8, i32 1)
%10 = tail call i32 @dup2(i32 %8, i32 2)
%11 = tail call i32 @close(i32 %8)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}