#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 /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
char *calloc(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ lseek(int, unsigned int, int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ print_file_content(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd1, i, n = 0;
  char filename[16];
  char str_default[256];
  char *str_temp;
  unsigned int offset;
  int len_newstr;
  char str_new[256];
  fputs("Please, write a default string: \n", stdout);
  fgets(str_default, 256, stdin);
  fputs("Please, the filename to store string: ", stdout);
  scanf("%s", filename);
  if ((fd1 = open(filename, O_RDWR | O_CREAT, 0755)) == -1) {
    fprintf(stderr, "Err. when opening file %s\n", filename);
    exit(EXIT_FAILURE);
  }
  write(fd1, str_default, strlen(str_default));
  system("tput reset");
  for (i = 0; i < (strlen(str_default) - 1); i++)
    printf("byte %2d %c\n", i, str_default[i]);
  printf("Tot. byte: %d\n\n", (strlen(str_default) - 1));
  fputs("From which byte do you want to modify: ", stdout);
  scanf("%u", &offset);
  fputs("How many bytes: ", stdout);
  scanf("%d", &len_newstr);
  printf("Write a %d byte string to replace: ", len_newstr);
  scanf("%s", str_new);
  str_temp = calloc(strlen(str_default), sizeof(char));
  strcpy(str_temp, str_default);
  for (i = offset; i < strlen(str_default) - 1; i++) {
    str_temp[i] = str_new[n];
    n++;
  }
  lseek(fd1, offset, SEEK_SET);
  write(fd1, str_new, len_newstr);
  close(fd1);
  printf("original text: %s", str_default);
  fputs("replaced text: ", stdout);
  print_file_content(filename);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
lea    0xde0(%rip),%rdi
call   10a0 <fputs@plt>
lea    -0x130(%rbp),%rdi
mov    0x2da5(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   10c0 <fgets@plt>
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
lea    0xdd3(%rip),%rdi
call   10a0 <fputs@plt>
lea    -0x30(%rbp),%rsi
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   10f0 <scanf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
mov    0x2d7e(%rip),%rax
or     (%rax),%esi
mov    $0x1ed,%edx
call   1100 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    12b9 <main+0xc9>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xda3(%rip),%rsi
call   10e0 <fprintf@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24c(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x248(%rbp)
lea    -0x130(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x24c(%rbp),%edi
mov    -0x248(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
lea    0xd6d(%rip),%rdi
call   1070 <system@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x250(%rbp)
lea    -0x130(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x250(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1356 <main+0x166>
mov    -0x18(%rbp),%esi
movslq -0x18(%rbp),%rax
movsbl -0x130(%rbp,%rax,1),%edx
ff
lea    0xd2e(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1303 <main+0x113>
lea    -0x130(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%esi
sub    $0x1,%esi
lea    0xd0e(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2c34(%rip),%rax
mov    (%rax),%esi
lea    0xd07(%rip),%rdi
call   10a0 <fputs@plt>
lea    0xd23(%rip),%rdi
lea    -0x13c(%rbp),%rsi
mov    $0x0,%al
call   10f0 <scanf@plt>
mov    0x2c0a(%rip),%rax
mov    (%rax),%esi
lea    0xd08(%rip),%rdi
call   10a0 <fputs@plt>
lea    0xd0d(%rip),%rdi
lea    -0x140(%rbp),%rsi
mov    $0x0,%al
call   10f0 <scanf@plt>
mov    -0x140(%rbp),%esi
lea    0xcf5(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x240(%rbp),%rsi
lea    0xd13(%rip),%rdi
mov    $0x0,%al
call   10f0 <scanf@plt>
lea    -0x130(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   10d0 <calloc@plt>
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rdi
lea    -0x130(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x13c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x254(%rbp)
lea    -0x130(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x254(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1485 <main+0x295>
movslq -0x1c(%rbp),%rax
mov    -0x240(%rbp,%rax,1),%dl
mov    -0x138(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    142d <main+0x23d>
mov    -0x14(%rbp),%edi
mov    -0x13c(%rbp),%esi
mov    0x2b2b(%rip),%rax
mov    (%rax),%edx
call   1090 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    -0x240(%rbp),%rsi
mov    -0x140(%rbp),%edx
call   1050 <write@plt>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
lea    -0x130(%rbp),%rsi
lea    0xc28(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2adb(%rip),%rax
mov    (%rax),%esi
lea    0xc23(%rip),%rdi
call   10a0 <fputs@plt>
lea    -0x30(%rbp),%rdi
call   1030 <print_file_content@plt>
mov    0x2ab5(%rip),%rax
mov    (%rax),%eax
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    0x2da8(%rip),%r12
mov    (%r12),%esi
lea    0xded(%rip),%rdi
call   10a0 <fputs@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%rdi
mov    $0x100,%esi
call   10c0 <fgets@plt>
mov    (%r12),%esi
lea    0xde7(%rip),%rdi
call   10a0 <fputs@plt>
lea    0xeb7(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   10f0 <scanf@plt>
mov    0x2d83(%rip),%rax
mov    0x2d94(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1ed,%edx
call   1100 <open@plt>
cmp    $0xffffffff,%eax
je     146b <main+0x27b>
mov    %eax,%r15d
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
lea    0xdc2(%rip),%rdi
call   1070 <system@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    $0x2,%eax
jl     12f7 <main+0x107>
lea    0xdb4(%rip),%r14
lea    0x20(%rsp),%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl 0x20(%rsp,%rbx,1),%edx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1080 <printf@plt>
add    $0x1,%rbx
mov    %rbp,%rdi
call   1060 <strlen@plt>
add    $0xffffffff,%eax
cltq
cmp    %rax,%rbx
jl     12d0 <main+0xe0>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    -0x1(%rax),%esi
lea    0xd6e(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%r12),%esi
lea    0xd6c(%rip),%rdi
call   10a0 <fputs@plt>
lea    0xd88(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   10f0 <scanf@plt>
mov    (%r12),%esi
lea    0xd74(%rip),%rdi
call   10a0 <fputs@plt>
lea    0xd79(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   10f0 <scanf@plt>
mov    0x8(%rsp),%esi
lea    0xd65(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd8a(%rip),%rdi
lea    0x120(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   10f0 <scanf@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   10d0 <calloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
movslq 0xc(%rsp),%rbp
mov    %r14,%rdi
call   1060 <strlen@plt>
add    $0xffffffff,%eax
cmp    %eax,%ebp
jge    13f2 <main+0x202>
lea    0x20(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
mov    %al,0x0(%r13,%rbp,1)
add    $0x1,%rbp
mov    %r14,%rdi
call   1060 <strlen@plt>
add    $0xffffffff,%eax
cltq
add    $0x1,%rbx
cmp    %rax,%rbp
jl     13d0 <main+0x1e0>
mov    0xc(%rsp),%esi
mov    0x2bc3(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
call   1090 <lseek@plt>
mov    0x8(%rsp),%edx
lea    0x120(%rsp),%rsi
mov    %r15d,%edi
call   1050 <write@plt>
mov    %r15d,%edi
call   10b0 <close@plt>
lea    0xcc5(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%r12),%esi
lea    0xcc0(%rip),%rdi
call   10a0 <fputs@plt>
lea    0x10(%rsp),%rdi
call   1030 <print_file_content@plt>
mov    0x2b51(%rip),%rax
mov    (%rax),%eax
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b56(%rip),%rax
mov    (%rax),%edi
lea    0xbce(%rip),%rsi
lea    0x10(%rsp),%rdx
call   10e0 <fprintf@plt>
mov    0x2b2c(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"Please, write a default string: \0A\00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [39 x i8] c"Please, the filename to store string: \00"
@.str.2 = [3 x i8] c"%s\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str.3 = [27 x i8] c"Err. when opening file %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [11 x i8] c"tput reset\00"
@.str.5 = [13 x i8] c"byte %2d %c\0A\00"
@.str.6 = [16 x i8] c"Tot. byte: %d\0A\0A\00"
@.str.7 = [40 x i8] c"From which byte do you want to modify: \00"
@.str.8 = [3 x i8] c"%u\00"
@.str.9 = [17 x i8] c"How many bytes: \00"
@.str.10 = [3 x i8] c"%d\00"
@.str.11 = [36 x i8] c"Write a %d byte string to replace: \00"
@SEEK_SET = global i32 0
@.str.12 = [18 x i8] c"original text: %s\00"
@.str.13 = [16 x i8] c"replaced text: \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 i32
%9 = alloca [16 x i8]
%10 = alloca [256 x i8]
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%15 = load i32, i32* @stdout
%16 = call i32 @fputs(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %17, i32 256, i32 %18)
%20 = load i32, i32* @stdout
%21 = call i32 @fputs(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%25 = load i32, i32* @O_RDWR
%26 = load i32, i32* @O_CREAT
%27 = or i32 %25, %26
%28 = call i32 @open(i8* %24, i32 %27, i32 493)
store i32 %28, i32* %6
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %36
30: ; preds = %2
%31 = load i32, i32* @stderr
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %2
%37 = load i32, i32* %6
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = call i32 @write(i32 %37, i8* %38, i32 %40)
%42 = call i32 @system(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %7
br label %43
43: ; preds = %57, %36
%44 = load i32, i32* %7
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%46 = call i32 @strlen(i8* %45)
%47 = sub nsw i32 %46, 1
%48 = icmp slt i32 %44, %47
br i1 %48, label %49, label %60
49: ; preds = %43
%50 = load i32, i32* %7
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %50, i32 %55)
br label %57
57: ; preds = %49
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %43
60: ; preds = %43
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%62 = call i32 @strlen(i8* %61)
%63 = sub nsw i32 %62, 1
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %63)
%65 = load i32, i32* @stdout
%66 = call i32 @fputs(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i32 %65)
%67 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %12)
%68 = load i32, i32* @stdout
%69 = call i32 @fputs(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 %68)
%70 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32* %13)
%71 = load i32, i32* %13
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.11, i64 0, i64 0), i32 %71)
%73 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%74 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %73)
%75 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%76 = call i32 @strlen(i8* %75)
%77 = call i8* @calloc(i32 %76, i32 1)
store i8* %77, i8** %11
%78 = load i8*, i8** %11
%79 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%80 = call i32 @strcpy(i8* %78, i8* %79)
%81 = load i32, i32* %12
store i32 %81, i32* %7
br label %82
82: ; preds = %99, %60
%83 = load i32, i32* %7
%84 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%85 = call i32 @strlen(i8* %84)
%86 = sub nsw i32 %85, 1
%87 = icmp slt i32 %83, %86
br i1 %87, label %88, label %102
88: ; preds = %82
%89 = load i32, i32* %8
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 %90
%92 = load i8, i8* %91
%93 = load i8*, i8** %11
%94 = load i32, i32* %7
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8, i8* %93, i64 %95
store i8 %92, i8* %96
%97 = load i32, i32* %8
%98 = add nsw i32 %97, 1
store i32 %98, i32* %8
br label %99
99: ; preds = %88
%100 = load i32, i32* %7
%101 = add nsw i32 %100, 1
store i32 %101, i32* %7
br label %82
102: ; preds = %82
%103 = load i32, i32* %6
%104 = load i32, i32* %12
%105 = load i32, i32* @SEEK_SET
%106 = call i32 @lseek(i32 %103, i32 %104, i32 %105)
%107 = load i32, i32* %6
%108 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%109 = load i32, i32* %13
%110 = call i32 @write(i32 %107, i8* %108, i32 %109)
%111 = load i32, i32* %6
%112 = call i32 @close(i32 %111)
%113 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i8* %113)
%115 = load i32, i32* @stdout
%116 = call i32 @fputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0), i32 %115)
%117 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%118 = call i32 @print_file_content(i8* %117)
%119 = load i32, i32* @EXIT_SUCCESS
ret i32 %119
}

LLVM IR (-O2):
@.str = [34 x i8] c"Please, write a default string: \0A\00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [39 x i8] c"Please, the filename to store string: \00"
@.str.2 = [3 x i8] c"%s\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str.3 = [27 x i8] c"Err. when opening file %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [11 x i8] c"tput reset\00"
@.str.5 = [13 x i8] c"byte %2d %c\0A\00"
@.str.6 = [16 x i8] c"Tot. byte: %d\0A\0A\00"
@.str.7 = [40 x i8] c"From which byte do you want to modify: \00"
@.str.8 = [3 x i8] c"%u\00"
@.str.9 = [17 x i8] c"How many bytes: \00"
@.str.10 = [3 x i8] c"%d\00"
@.str.11 = [36 x i8] c"Write a %d byte string to replace: \00"
@SEEK_SET = global i32 0
@.str.12 = [18 x i8] c"original text: %s\00"
@.str.13 = [16 x i8] c"replaced text: \00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [16 x i8]
%4 = alloca [256 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%13 = load i32, i32* @stdout
%14 = tail call i32 @fputs(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* %9, i32 256, i32 %15)
%17 = load i32, i32* @stdout
%18 = call i32 @fputs(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%20 = load i32, i32* @O_RDWR
%21 = load i32, i32* @O_CREAT
%22 = or i32 %21, %20
%23 = call i32 @open(i8* %8, i32 %22, i32 493)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %30
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %2
%31 = call i32 @strlen(i8* %9)
%32 = call i32 @write(i32 %23, i8* %9, i32 %31)
%33 = call i32 @system(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 @strlen(i8* %9)
%35 = icmp sgt i32 %34, 1
br i1 %35, label %36, label %48
36: ; preds = %30, %36
%37 = phi i64 [ %43, %36 ], [ 0, %30 ]
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = trunc i64 %37 to i32
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %41, i32 %40)
%43 = add nuw nsw i64 %37, 1
%44 = call i32 @strlen(i8* %9)
%45 = add nsw i32 %44, -1
%46 = sext i32 %45 to i64
%47 = icmp slt i64 %43, %46
br i1 %47, label %36, label %48
48: ; preds = %36, %30
%49 = call i32 @strlen(i8* %9)
%50 = add nsw i32 %49, -1
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %50)
%52 = load i32, i32* @stdout
%53 = call i32 @fputs(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i32 %52)
%54 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %5)
%55 = load i32, i32* @stdout
%56 = call i32 @fputs(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 %55)
%57 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32* %6)
%58 = load i32, i32* %6
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.11, i64 0, i64 0), i32 %58)
%60 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%61 = call i32 @strlen(i8* %9)
%62 = call i8* @calloc(i32 %61, i32 1)
%63 = call i32 @strcpy(i8* %62, i8* %9)
%64 = load i32, i32* %5
%65 = call i32 @strlen(i8* %9)
%66 = add nsw i32 %65, -1
%67 = icmp slt i32 %64, %66
br i1 %67, label %68, label %82
68: ; preds = %48
%69 = sext i32 %64 to i64
br label %70
70: ; preds = %68, %70
%71 = phi i64 [ 0, %68 ], [ %76, %70 ]
%72 = phi i64 [ %69, %68 ], [ %77, %70 ]
%73 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %71
%74 = load i8, i8* %73
%75 = getelementptr inbounds i8, i8* %62, i64 %72
store i8 %74, i8* %75
%76 = add nuw nsw i64 %71, 1
%77 = add nsw i64 %72, 1
%78 = call i32 @strlen(i8* %9)
%79 = add nsw i32 %78, -1
%80 = sext i32 %79 to i64
%81 = icmp slt i64 %77, %80
br i1 %81, label %70, label %82
82: ; preds = %70, %48
%83 = load i32, i32* %5
%84 = load i32, i32* @SEEK_SET
%85 = call i32 @lseek(i32 %23, i32 %83, i32 %84)
%86 = load i32, i32* %6
%87 = call i32 @write(i32 %23, i8* %12, i32 %86)
%88 = call i32 @close(i32 %23)
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i8* %9)
%90 = load i32, i32* @stdout
%91 = call i32 @fputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0), i32 %90)
%92 = call i32 @print_file_content(i8* %8)
%93 = load i32, i32* @EXIT_SUCCESS
ret i32 %93
}