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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char **, int);
int /*<<< orphan*/ stderr;
scalar_t__ write(int, char **, int);
int main(int argc, char *argv[]) {
  int fd1, fd2;
  char *input_file = "/etc/passwd";
  char *output_file = "new_passwd.txt";
  char buf[1413];
  ssize_t num_read;
  if ((fd1 = open(input_file, O_RDONLY)) < 0) {
    printf("Err. apertura %s\n", input_file);
    exit(EXIT_FAILURE);
  }
  if ((fd2 = open(output_file, O_RDWR | O_CREAT, 0644)) < 0) {
    printf("Err. apertura %s\n", input_file);
    exit(EXIT_FAILURE);
  }
  if (lseek(fd1, 32, SEEK_SET) == -1) {
    printf("Err. lseek()\n");
    exit(EXIT_FAILURE);
  }
  if ((num_read = read(fd1, &buf, 1413)) < 0) {
    fprintf(stderr, "Err. read\n");
    exit(EXIT_FAILURE);
  }
  if (write(fd2, &buf, (1413 - 32)) < 0) {
    fprintf(stderr, "Err. write\n");
    exit(EXIT_FAILURE);
  }
  close(fd1);
  close(fd2);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe61(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11ef <main+0x6f>
mov    -0x20(%rbp),%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
mov    0x2df5(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    123d <main+0xbd>
mov    -0x20(%rbp),%rsi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2d79(%rip),%rax
mov    (%rax),%edx
mov    $0x20,%esi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1278 <main+0xf8>
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x5b0(%rbp),%rsi
mov    $0x585,%edx
call   1070 <read@plt>
mov    %eax,-0x5b4(%rbp)
cmp    $0x0,%eax
jge    12be <main+0x13e>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
lea    0xd90(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x5b0(%rbp),%rsi
mov    $0x565,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    12ff <main+0x17f>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
lea    0xd5a(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2cc0(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    0x2c9a(%rip),%rax
mov    (%rax),%eax
add    $0x5c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x588,%rsp
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
lea    0xe57(%rip),%rdi
xor    %eax,%eax
call   10a0 <open@plt>
test   %eax,%eax
js     1247 <main+0xb7>
mov    %eax,%ebx
mov    0x2e1f(%rip),%rax
mov    0x2e30(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe39(%rip),%rdi
mov    $0x1a4,%edx
xor    %eax,%eax
call   10a0 <open@plt>
test   %eax,%eax
js     1247 <main+0xb7>
mov    %eax,%ebp
mov    0x2dd4(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x20,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
je     125e <main+0xce>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x585,%edx
call   1080 <read@plt>
test   %eax,%eax
js     126c <main+0xdc>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x565,%edx
call   1040 <write@plt>
test   %rax,%rax
js     127e <main+0xee>
mov    %ebx,%edi
call   1070 <close@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%eax
add    $0x588,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdcd(%rip),%rdi
lea    0xdab(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1293 <main+0x103>
lea    0xddf(%rip),%rdi
call   1030 <puts@plt>
jmp    1293 <main+0x103>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
lea    0xdb1(%rip),%rsi
jmp    128e <main+0xfe>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xdaa(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/etc/passwd\00"
@.str.1 = [15 x i8] c"new_passwd.txt\00"
@O_RDONLY = global i32 0
@.str.2 = [18 x i8] c"Err. apertura %s\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [14 x i8] c"Err. lseek()\0A\00"
@stderr = global i32 0
@.str.4 = [11 x i8] c"Err. read\0A\00"
@.str.5 = [12 x i8] c"Err. write\0A\00"
@EXIT_SUCCESS = global i32 0
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 i8*
%10 = alloca [1413 x i8]
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %9
%12 = load i8*, i8** %8
%13 = load i32, i32* @O_RDONLY
%14 = call i32 (i8*, i32, ...) @open(i8* %12, i32 %13)
store i32 %14, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8*, i8** %8
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i8*, i8** %9
%23 = load i32, i32* @O_RDWR
%24 = load i32, i32* @O_CREAT
%25 = or i32 %23, %24
%26 = call i32 (i8*, i32, ...) @open(i8* %22, i32 %25, i32 420)
store i32 %26, i32* %7
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %21
%29 = load i8*, i8** %8
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %21
%34 = load i32, i32* %6
%35 = load i32, i32* @SEEK_SET
%36 = call i32 @lseek(i32 %34, i32 32, i32 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %33
%43 = load i32, i32* %6
%44 = bitcast [1413 x i8]* %10 to i8**
%45 = call i32 @read(i32 %43, i8** %44, i32 1413)
store i32 %45, i32* %11
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %42
%53 = load i32, i32* %7
%54 = bitcast [1413 x i8]* %10 to i8**
%55 = call i64 @write(i32 %53, i8** %54, i32 1381)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %52
%58 = load i32, i32* @stderr
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %52
%63 = load i32, i32* %6
%64 = call i32 @close(i32 %63)
%65 = load i32, i32* %7
%66 = call i32 @close(i32 %65)
%67 = load i32, i32* @EXIT_SUCCESS
ret i32 %67
}

LLVM IR (-O2):
@.str = [12 x i8] c"/etc/passwd\00"
@.str.1 = [15 x i8] c"new_passwd.txt\00"
@O_RDONLY = global i32 0
@.str.2 = [18 x i8] c"Err. apertura %s\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str.4 = [11 x i8] c"Err. read\0A\00"
@.str.5 = [12 x i8] c"Err. write\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [13 x i8] c"Err. lseek()\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1413 x i8]
%4 = getelementptr inbounds [1413 x i8], [1413 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = load i32, i32* @O_RDWR
%14 = load i32, i32* @O_CREAT
%15 = or i32 %14, %13
%16 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 420)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %12
%23 = load i32, i32* @SEEK_SET
%24 = tail call i32 @lseek(i32 %6, i32 32, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %22
%31 = bitcast [1413 x i8]* %3 to i8**
%32 = call i32 @read(i32 %6, i8** %31, i32 1413)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = tail call i32 @exit(i32 %37)
unreachable
39: ; preds = %30
%40 = call i64 @write(i32 %16, i8** %31, i32 1381)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = tail call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%45 = load i32, i32* @EXIT_FAILURE
%46 = tail call i32 @exit(i32 %45)
unreachable
47: ; preds = %39
%48 = tail call i32 @close(i32 %6)
%49 = tail call i32 @close(i32 %16)
%50 = load i32, i32* @EXIT_SUCCESS
ret i32 %50
}