#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*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int BUFSIZ;
scalar_t__ EOF;
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fcopy(char *, char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ fputs(char *, int /*<<< orphan*/ *);
scalar_t__ rename(char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int strlen(char const *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *strstr(char *, char const *);
int grub_remove_nouveau_nomodeset() {
  FILE *fp, *fpnew;
  char buffer[BUFSIZ];
  char bufnew[BUFSIZ + 128];
  const char *nouveau_modeset_zero = "nouveau.modeset=0 ";
  const char *nouveau_modeset_zero_notrail = "nouveau.modeset=0";
  const char *grub_cmdline_linux_default = "GRUB_CMDLINE_LINUX_DEFAULT=\"";
  char *pos, *match;
  size_t l, l1, l2;
  l = strlen(grub_cmdline_linux_default);
  l1 = strlen(nouveau_modeset_zero);
  l2 = strlen(nouveau_modeset_zero_notrail);
  if ((fcopy("/etc/default/grub",
             "/etc/default/grub.bak.nvidiaprime.removed")) != 0) {
    fprintf(stderr,
            "Can't copy /etc/default/grub to "
            "/etc/default/grub.temp.nvidiaprime.removed: %s (error: %d)\n",
            strerror(errno), errno);
    return (1);
  }
  if ((fp = fopen("/etc/default/grub.bak.nvidiaprime.removed", "r")) == NULL) {
    fprintf(stderr,
            "Can't open file /etc/default/grub.bak.nvidiaprime.removed: %s "
            "(error %d)\n",
            strerror(errno), errno);
    return (1);
  }
  if ((fpnew = fopen("/etc/default/grub.temp.nvidiaprime", "w")) == NULL) {
    fprintf(stderr, "Can't open file /etc/default/grub.temp.nvidiaprime");
    fclose(fp);
    return (1);
  }
  while (fgets(buffer, sizeof(buffer), fp) != NULL) {
    *(bufnew) = '\0';
    if ((pos = strstr(buffer, grub_cmdline_linux_default))) {
      strncpy(bufnew, buffer, l);
      *(bufnew + l) = '\0';
      if ((match = strstr(pos + l, nouveau_modeset_zero))) {
        strncat(bufnew, pos + l, match - (pos + l));
        strncat(bufnew, match + l1, strlen(match + l1));
      } else if ((match = strstr(pos + l, nouveau_modeset_zero_notrail))) {
        strncat(bufnew, pos + l, match - (pos + l));
        strncat(bufnew, match + l2, strlen(match + l2));
      } else {
        strncat(bufnew, pos + l, strlen(pos + l));
      }
      if ((fputs(bufnew, fpnew)) == EOF) {
        fprintf(stderr,
                "Can't write on file: /etc/default/grub.temp.nvidiaprime: %s "
                "(error %d)\n",
                strerror(errno), errno);
        break;
      }
    } else {
      if ((fputs(buffer, fpnew)) == EOF) {
        fprintf(stderr,
                "Can't write on file: /etc/default/grub.temp.nvidiaprime: %s "
                "(error %d)\n",
                strerror(errno), errno);
        break;
      }
    }
  }
  fclose(fp);
  fclose(fpnew);
  if ((rename("/etc/default/grub.temp.nvidiaprime", "/etc/default/grub")) !=
      0) {
    fprintf(stderr,
            "Can't rename /etc/default/grub.temp.nvidiaprime to "
            "/etc/default/grub: %s (error %d)\n",
            strerror(errno), errno);
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<grub_remove_nouveau_nomodeset>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    0x2dfe(%rip),%rax
mov    (%rax),%ecx
mov    %rcx,-0x90(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x88(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x28(%rbp)
mov    (%rax),%eax
sub    $0xffffff80,%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
lea    0xdd7(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xddf(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xde6(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1050 <strlen@plt>
cltq
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
cltq
mov    %rax,-0x68(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
cltq
mov    %rax,-0x70(%rbp)
lea    0xdcb(%rip),%rdi
lea    0xdd6(%rip),%rsi
call   10a0 <fcopy@plt>
cmp    $0x0,%rax
je     12dd <grub_remove_nouveau_nomodeset+0x11d>
mov    0x2d44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x94(%rbp),%edi
mov    %rax,%rdx
mov    0x2d0e(%rip),%rax
mov    (%rax),%ecx
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x74(%rbp)
jmp    1687 <grub_remove_nouveau_nomodeset+0x4c7>
lea    0xd70(%rip),%rdi
lea    0xdef(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    134e <grub_remove_nouveau_nomodeset+0x18e>
mov    0x2cd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x98(%rbp)
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x98(%rbp),%edi
mov    %rax,%rdx
mov    0x2c9d(%rip),%rax
mov    (%rax),%ecx
lea    0xda8(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x74(%rbp)
jmp    1687 <grub_remove_nouveau_nomodeset+0x4c7>
lea    0xde3(%rip),%rdi
lea    0xdca(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    13a2 <grub_remove_nouveau_nomodeset+0x1e2>
mov    0x2c62(%rip),%rax
mov    (%rax),%edi
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x74(%rbp)
jmp    1687 <grub_remove_nouveau_nomodeset+0x4c7>
jmp    13a7 <grub_remove_nouveau_nomodeset+0x1e7>
mov    -0x88(%rbp),%rdi
mov    -0x90(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     15fa <grub_remove_nouveau_nomodeset+0x43a>
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x48(%rbp),%rsi
call   10e0 <strstr@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
je     158e <grub_remove_nouveau_nomodeset+0x3ce>
mov    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%rsi
mov    -0x60(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x80(%rbp),%rax
mov    -0x60(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x50(%rbp),%rdi
add    -0x60(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   10e0 <strstr@plt>
mov    %rax,-0x58(%rbp)
cmp    $0x0,%rax
je     1483 <grub_remove_nouveau_nomodeset+0x2c3>
mov    -0x80(%rbp),%rdi
mov    -0x50(%rbp),%rsi
add    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rax
mov    -0x50(%rbp),%rcx
add    -0x60(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1070 <strncat@plt>
mov    -0x58(%rbp),%rax
add    -0x68(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x58(%rbp),%rdi
add    -0x68(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x80(%rbp),%rdi
mov    -0xa0(%rbp),%rsi
mov    %eax,%edx
call   1070 <strncat@plt>
jmp    152a <grub_remove_nouveau_nomodeset+0x36a>
mov    -0x50(%rbp),%rdi
add    -0x60(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   10e0 <strstr@plt>
mov    %rax,-0x58(%rbp)
cmp    $0x0,%rax
je     14f7 <grub_remove_nouveau_nomodeset+0x337>
mov    -0x80(%rbp),%rdi
mov    -0x50(%rbp),%rsi
add    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rax
mov    -0x50(%rbp),%rcx
add    -0x60(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1070 <strncat@plt>
mov    -0x58(%rbp),%rax
add    -0x70(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x58(%rbp),%rdi
add    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x80(%rbp),%rdi
mov    -0xa8(%rbp),%rsi
mov    %eax,%edx
call   1070 <strncat@plt>
jmp    1525 <grub_remove_nouveau_nomodeset+0x365>
mov    -0x50(%rbp),%rax
add    -0x60(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x50(%rbp),%rdi
add    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x80(%rbp),%rdi
mov    -0xb0(%rbp),%rsi
mov    %eax,%edx
call   1070 <strncat@plt>
jmp    152a <grub_remove_nouveau_nomodeset+0x36a>
mov    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <fputs@plt>
mov    0x2aaa(%rip),%rcx
cmp    (%rcx),%rax
jne    1589 <grub_remove_nouveau_nomodeset+0x3c9>
mov    0x2a8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb4(%rbp)
mov    0x2a6b(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0xb4(%rbp),%edi
mov    %rax,%rdx
mov    0x2a54(%rip),%rax
mov    (%rax),%ecx
lea    0xbde(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    15fa <grub_remove_nouveau_nomodeset+0x43a>
jmp    15f5 <grub_remove_nouveau_nomodeset+0x435>
mov    -0x88(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <fputs@plt>
mov    0x2a43(%rip),%rcx
cmp    (%rcx),%rax
jne    15f0 <grub_remove_nouveau_nomodeset+0x430>
mov    0x2a23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb8(%rbp)
mov    0x2a04(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0xb8(%rbp),%edi
mov    %rax,%rdx
mov    0x29ed(%rip),%rax
mov    (%rax),%ecx
lea    0xb77(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    15fa <grub_remove_nouveau_nomodeset+0x43a>
jmp    15f5 <grub_remove_nouveau_nomodeset+0x435>
jmp    13a7 <grub_remove_nouveau_nomodeset+0x1e7>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xb25(%rip),%rdi
lea    0xa28(%rip),%rsi
call   10c0 <rename@plt>
cmp    $0x0,%rax
je     1679 <grub_remove_nouveau_nomodeset+0x4b9>
mov    0x29a8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xbc(%rbp)
mov    0x2989(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0xbc(%rbp),%edi
mov    %rax,%rdx
mov    0x2972(%rip),%rax
mov    (%rax),%ecx
lea    0xb44(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x74(%rbp)
jmp    1687 <grub_remove_nouveau_nomodeset+0x4c7>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x74(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grub_remove_nouveau_nomodeset>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    0x2df8(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r15
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0x80(%r14),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    0xe17(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x48(%rbp)
lea    0xde3(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
lea    0xde8(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
lea    0xe08(%rip),%rdi
lea    0xe13(%rip),%rsi
call   10a0 <fcopy@plt>
test   %rax,%rax
je     128d <grub_remove_nouveau_nomodeset+0xcd>
mov    0x2d86(%rip),%rax
mov    (%rax),%ebx
mov    0x2d6d(%rip),%r14
mov    (%r14),%edi
call   10d0 <strerror@plt>
mov    (%r14),%ecx
lea    0xe11(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12d,-0x38(%rbp)
mov    -0x48(%rbp),%r12d
lea    0xdb8(%rip),%rdi
lea    0xe37(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
test   %rax,%rax
je     140a <grub_remove_nouveau_nomodeset+0x24a>
lea    0xe7c(%rip),%rdi
lea    0xe63(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x50(%rbp)
test   %rax,%rax
je     1431 <grub_remove_nouveau_nomodeset+0x271>
mov    %r15,%rdi
mov    %r14d,%esi
mov    -0x30(%rbp),%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1484 <grub_remove_nouveau_nomodeset+0x2c4>
movslq %r12d,%rax
mov    %rax,-0x48(%rbp)
movslq %ebx,%rax
mov    %rax,-0x58(%rbp)
movslq -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    %r14,-0x40(%rbp)
mov    -0x48(%rbp),%rbx
nopl   0x0(%rax,%rax,1)
movb   $0x0,0x0(%r13)
mov    %r15,%rdi
lea    0xd06(%rip),%rsi
call   10e0 <strstr@plt>
test   %rax,%rax
je     1380 <grub_remove_nouveau_nomodeset+0x1c0>
mov    %rax,%r12
mov    %r13,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
movb   $0x0,0x0(%r13,%rbx,1)
add    %rbx,%r12
mov    %r12,%rdi
lea    0xcb3(%rip),%rsi
call   10e0 <strstr@plt>
test   %rax,%rax
je     1390 <grub_remove_nouveau_nomodeset+0x1d0>
mov    %rax,%r14
mov    %r14d,%edx
sub    %r12d,%edx
mov    %r13,%rdi
mov    %r12,%rsi
call   1070 <strncat@plt>
add    -0x58(%rbp),%r14
jmp    13bc <grub_remove_nouveau_nomodeset+0x1fc>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
jmp    13db <grub_remove_nouveau_nomodeset+0x21b>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
lea    0xc79(%rip),%rsi
call   10e0 <strstr@plt>
test   %rax,%rax
je     13bf <grub_remove_nouveau_nomodeset+0x1ff>
mov    %rax,%r14
mov    %r14d,%edx
sub    %r12d,%edx
mov    %r13,%rdi
mov    %r12,%rsi
call   1070 <strncat@plt>
add    -0x38(%rbp),%r14
mov    %r14,%r12
mov    -0x40(%rbp),%r14
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1070 <strncat@plt>
mov    %r13,%rdi
mov    -0x50(%rbp),%rsi
call   1060 <fputs@plt>
mov    0x2bfd(%rip),%rcx
cmp    (%rcx),%rax
je     1456 <grub_remove_nouveau_nomodeset+0x296>
mov    %r15,%rdi
mov    %r14d,%esi
mov    -0x30(%rbp),%rdx
call   1080 <fgets@plt>
test   %rax,%rax
jne    1310 <grub_remove_nouveau_nomodeset+0x150>
jmp    1484 <grub_remove_nouveau_nomodeset+0x2c4>
mov    0x2bc7(%rip),%rax
mov    (%rax),%ebx
mov    0x2bae(%rip),%r14
mov    (%r14),%edi
call   10d0 <strerror@plt>
mov    (%r14),%ecx
lea    0xcb0(%rip),%rsi
jmp    126d <grub_remove_nouveau_nomodeset+0xad>
mov    0x2ba0(%rip),%rax
mov    (%rax),%edi
lea    0xce7(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1279 <grub_remove_nouveau_nomodeset+0xb9>
mov    0x2b7b(%rip),%rax
mov    (%rax),%ebx
mov    0x2b62(%rip),%r14
mov    (%r14),%edi
call   10d0 <strerror@plt>
mov    (%r14),%ecx
lea    0xce3(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x50(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xc9b(%rip),%rdi
lea    0xb9e(%rip),%rsi
call   10c0 <rename@plt>
test   %rax,%rax
je     14d5 <grub_remove_nouveau_nomodeset+0x315>
mov    0x2b23(%rip),%rax
mov    (%rax),%ebx
mov    0x2b0a(%rip),%r14
mov    (%r14),%edi
call   10d0 <strerror@plt>
mov    (%r14),%ecx
lea    0xcd3(%rip),%rsi
jmp    126d <grub_remove_nouveau_nomodeset+0xad>
xor    %eax,%eax
jmp    127e <grub_remove_nouveau_nomodeset+0xbe>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [19 x i8] c"nouveau.modeset=0 \00"
@.str.1 = [18 x i8] c"nouveau.modeset=0\00"
@.str.2 = [29 x i8] c"GRUB_CMDLINE_LINUX_DEFAULT=\22\00"
@.str.3 = [18 x i8] c"/etc/default/grub\00"
@.str.4 = [42 x i8] c"/etc/default/grub.bak.nvidiaprime.removed\00"
@stderr = global i32 0
@.str.5 = [92 x i8] c"Can't copy /etc/default/grub to /etc/default/grub.temp.nvidiaprime.removed: %s (error: %d)\0A\00"
@errno = global i32 0
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [74 x i8] c"Can't open file /etc/default/grub.bak.nvidiaprime.removed: %s (error %d)\0A\00"
@.str.8 = [35 x i8] c"/etc/default/grub.temp.nvidiaprime\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [51 x i8] c"Can't open file /etc/default/grub.temp.nvidiaprime\00"
@EOF = global i64 0
@.str.11 = [72 x i8] c"Can't write on file: /etc/default/grub.temp.nvidiaprime: %s (error %d)\0A\00"
@.str.12 = [85 x i8] c"Can't rename /etc/default/grub.temp.nvidiaprime to /etc/default/grub: %s (error %d)\0A\00"
define i32 @grub_remove_nouveau_nomodeset() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i32
%16 = load i32, i32* @BUFSIZ
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %4
%19 = alloca i8, i64 %17
store i64 %17, i64* %5
%20 = load i32, i32* @BUFSIZ
%21 = add nsw i32 %20, 128
%22 = zext i32 %21 to i64
%23 = alloca i8, i64 %22
store i64 %22, i64* %6
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8** %9
%24 = load i8*, i8** %9
%25 = call i32 @strlen(i8* %24)
%26 = sext i32 %25 to i64
store i64 %26, i64* %12
%27 = load i8*, i8** %7
%28 = call i32 @strlen(i8* %27)
%29 = sext i32 %28 to i64
store i64 %29, i64* %13
%30 = load i8*, i8** %8
%31 = call i32 @strlen(i8* %30)
%32 = sext i32 %31 to i64
store i64 %32, i64* %14
%33 = call i64 @fcopy(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %0
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = load i32, i32* @errno
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.5, i64 0, i64 0), i8* %38, i32 %39)
store i32 1, i32* %1
store i32 1, i32* %15
br label %177
41: ; preds = %0
%42 = call i32* @fopen(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %42, i32** %2
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %50
44: ; preds = %41
%45 = load i32, i32* @stderr
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = load i32, i32* @errno
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.7, i64 0, i64 0), i8* %47, i32 %48)
store i32 1, i32* %1
store i32 1, i32* %15
br label %177
50: ; preds = %41
%51 = call i32* @fopen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %51, i32** %3
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %58
53: ; preds = %50
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.10, i64 0, i64 0))
%56 = load i32*, i32** %2
%57 = call i32 @fclose(i32* %56)
store i32 1, i32* %1
store i32 1, i32* %15
br label %177
58: ; preds = %50
br label %59
59: ; preds = %162, %58
%60 = trunc i64 %17 to i32
%61 = load i32*, i32** %2
%62 = call i32* @fgets(i8* %19, i32 %60, i32* %61)
%63 = icmp ne i32* %62, null
br i1 %63, label %64, label %163
64: ; preds = %59
store i8 0, i8* %23
%65 = load i8*, i8** %9
%66 = call i8* @strstr(i8* %19, i8* %65)
store i8* %66, i8** %10
%67 = icmp ne i8* %66, null
br i1 %67, label %68, label %150
68: ; preds = %64
%69 = load i64, i64* %12
%70 = call i32 @strncpy(i8* %23, i8* %19, i64 %69)
%71 = load i64, i64* %12
%72 = getelementptr inbounds i8, i8* %23, i64 %71
store i8 0, i8* %72
%73 = load i8*, i8** %10
%74 = load i64, i64* %12
%75 = getelementptr inbounds i8, i8* %73, i64 %74
%76 = load i8*, i8** %7
%77 = call i8* @strstr(i8* %75, i8* %76)
store i8* %77, i8** %11
%78 = icmp ne i8* %77, null
br i1 %78, label %79, label %100
79: ; preds = %68
%80 = load i8*, i8** %10
%81 = load i64, i64* %12
%82 = getelementptr inbounds i8, i8* %80, i64 %81
%83 = load i8*, i8** %11
%84 = load i8*, i8** %10
%85 = load i64, i64* %12
%86 = getelementptr inbounds i8, i8* %84, i64 %85
%87 = ptrtoint i8* %83 to i64
%88 = ptrtoint i8* %86 to i64
%89 = sub i64 %87, %88
%90 = trunc i64 %89 to i32
%91 = call i32 @strncat(i8* %23, i8* %82, i32 %90)
%92 = load i8*, i8** %11
%93 = load i64, i64* %13
%94 = getelementptr inbounds i8, i8* %92, i64 %93
%95 = load i8*, i8** %11
%96 = load i64, i64* %13
%97 = getelementptr inbounds i8, i8* %95, i64 %96
%98 = call i32 @strlen(i8* %97)
%99 = call i32 @strncat(i8* %23, i8* %94, i32 %98)
br label %138
100: ; preds = %68
%101 = load i8*, i8** %10
%102 = load i64, i64* %12
%103 = getelementptr inbounds i8, i8* %101, i64 %102
%104 = load i8*, i8** %8
%105 = call i8* @strstr(i8* %103, i8* %104)
store i8* %105, i8** %11
%106 = icmp ne i8* %105, null
br i1 %106, label %107, label %128
107: ; preds = %100
%108 = load i8*, i8** %10
%109 = load i64, i64* %12
%110 = getelementptr inbounds i8, i8* %108, i64 %109
%111 = load i8*, i8** %11
%112 = load i8*, i8** %10
%113 = load i64, i64* %12
%114 = getelementptr inbounds i8, i8* %112, i64 %113
%115 = ptrtoint i8* %111 to i64
%116 = ptrtoint i8* %114 to i64
%117 = sub i64 %115, %116
%118 = trunc i64 %117 to i32
%119 = call i32 @strncat(i8* %23, i8* %110, i32 %118)
%120 = load i8*, i8** %11
%121 = load i64, i64* %14
%122 = getelementptr inbounds i8, i8* %120, i64 %121
%123 = load i8*, i8** %11
%124 = load i64, i64* %14
%125 = getelementptr inbounds i8, i8* %123, i64 %124
%126 = call i32 @strlen(i8* %125)
%127 = call i32 @strncat(i8* %23, i8* %122, i32 %126)
br label %137
128: ; preds = %100
%129 = load i8*, i8** %10
%130 = load i64, i64* %12
%131 = getelementptr inbounds i8, i8* %129, i64 %130
%132 = load i8*, i8** %10
%133 = load i64, i64* %12
%134 = getelementptr inbounds i8, i8* %132, i64 %133
%135 = call i32 @strlen(i8* %134)
%136 = call i32 @strncat(i8* %23, i8* %131, i32 %135)
br label %137
137: ; preds = %128, %107
br label %138
138: ; preds = %137, %79
%139 = load i32*, i32** %3
%140 = call i64 @fputs(i8* %23, i32* %139)
%141 = load i64, i64* @EOF
%142 = icmp eq i64 %140, %141
br i1 %142, label %143, label %149
143: ; preds = %138
%144 = load i32, i32* @stderr
%145 = load i32, i32* @errno
%146 = call i8* @strerror(i32 %145)
%147 = load i32, i32* @errno
%148 = call i32 (i32, i8*, ...) @fprintf(i32 %144, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.11, i64 0, i64 0), i8* %146, i32 %147)
br label %163
149: ; preds = %138
br label %162
150: ; preds = %64
%151 = load i32*, i32** %3
%152 = call i64 @fputs(i8* %19, i32* %151)
%153 = load i64, i64* @EOF
%154 = icmp eq i64 %152, %153
br i1 %154, label %155, label %161
155: ; preds = %150
%156 = load i32, i32* @stderr
%157 = load i32, i32* @errno
%158 = call i8* @strerror(i32 %157)
%159 = load i32, i32* @errno
%160 = call i32 (i32, i8*, ...) @fprintf(i32 %156, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.11, i64 0, i64 0), i8* %158, i32 %159)
br label %163
161: ; preds = %150
br label %162
162: ; preds = %161, %149
br label %59
163: ; preds = %155, %143, %59
%164 = load i32*, i32** %2
%165 = call i32 @fclose(i32* %164)
%166 = load i32*, i32** %3
%167 = call i32 @fclose(i32* %166)
%168 = call i64 @rename(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%169 = icmp ne i64 %168, 0
br i1 %169, label %170, label %176
170: ; preds = %163
%171 = load i32, i32* @stderr
%172 = load i32, i32* @errno
%173 = call i8* @strerror(i32 %172)
%174 = load i32, i32* @errno
%175 = call i32 (i32, i8*, ...) @fprintf(i32 %171, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.12, i64 0, i64 0), i8* %173, i32 %174)
store i32 1, i32* %1
store i32 1, i32* %15
br label %177
176: ; preds = %163
store i32 0, i32* %1
store i32 1, i32* %15
br label %177
177: ; preds = %176, %170, %53, %44, %35
%178 = load i8*, i8** %4
%179 = load i32, i32* %1
ret i32 %179
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [19 x i8] c"nouveau.modeset=0 \00"
@.str.1 = [18 x i8] c"nouveau.modeset=0\00"
@.str.2 = [29 x i8] c"GRUB_CMDLINE_LINUX_DEFAULT=\22\00"
@.str.3 = [18 x i8] c"/etc/default/grub\00"
@.str.4 = [42 x i8] c"/etc/default/grub.bak.nvidiaprime.removed\00"
@stderr = global i32 0
@.str.5 = [92 x i8] c"Can't copy /etc/default/grub to /etc/default/grub.temp.nvidiaprime.removed: %s (error: %d)\0A\00"
@errno = global i32 0
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [74 x i8] c"Can't open file /etc/default/grub.bak.nvidiaprime.removed: %s (error %d)\0A\00"
@.str.8 = [35 x i8] c"/etc/default/grub.temp.nvidiaprime\00"
@.str.9 = [2 x i8] c"w\00"
@.str.10 = [51 x i8] c"Can't open file /etc/default/grub.temp.nvidiaprime\00"
@EOF = global i64 0
@.str.11 = [72 x i8] c"Can't write on file: /etc/default/grub.temp.nvidiaprime: %s (error %d)\0A\00"
@.str.12 = [85 x i8] c"Can't rename /etc/default/grub.temp.nvidiaprime to /etc/default/grub: %s (error %d)\0A\00"
define i32 @grub_remove_nouveau_nomodeset() {
%1 = load i32, i32* @BUFSIZ
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = add nsw i32 %1, 128
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%8 = sext i32 %7 to i64
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%10 = sext i32 %9 to i64
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%12 = sext i32 %11 to i64
%13 = tail call i64 @fcopy(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %0
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = load i32, i32* @errno
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.5, i64 0, i64 0), i8* %18, i32 %19)
br label %98
21: ; preds = %0
%22 = tail call i32* @fopen(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = tail call i8* @strerror(i32 %26)
%28 = load i32, i32* @errno
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.7, i64 0, i64 0), i8* %27, i32 %28)
br label %98
30: ; preds = %21
%31 = tail call i32* @fopen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %38, label %33
33: ; preds = %30
%34 = call i32* @fgets(i8* %3, i32 %1, i32* %22)
%35 = icmp eq i32* %34, null
br i1 %35, label %87, label %36
36: ; preds = %33
%37 = getelementptr inbounds i8, i8* %6, i64 %8
br label %42
38: ; preds = %30
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.10, i64 0, i64 0))
%41 = tail call i32 @fclose(i32* %22)
br label %98
42: ; preds = %36, %78
store i8 0, i8* %6
%43 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%44 = icmp eq i8* %43, null
br i1 %44, label %74, label %45
45: ; preds = %42
%46 = call i32 @strncpy(i8* %6, i8* %3, i64 %8)
store i8 0, i8* %37
%47 = getelementptr inbounds i8, i8* %43, i64 %8
%48 = call i8* @strstr(i8* %47, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%49 = icmp eq i8* %48, null
br i1 %49, label %57, label %50
50: ; preds = %45
%51 = ptrtoint i8* %48 to i64
%52 = ptrtoint i8* %47 to i64
%53 = sub i64 %51, %52
%54 = trunc i64 %53 to i32
%55 = call i32 @strncat(i8* %6, i8* %47, i32 %54)
%56 = getelementptr inbounds i8, i8* %48, i64 %10
br label %67
57: ; preds = %45
%58 = call i8* @strstr(i8* %47, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%59 = icmp eq i8* %58, null
br i1 %59, label %67, label %60
60: ; preds = %57
%61 = ptrtoint i8* %58 to i64
%62 = ptrtoint i8* %47 to i64
%63 = sub i64 %61, %62
%64 = trunc i64 %63 to i32
%65 = call i32 @strncat(i8* %6, i8* %47, i32 %64)
%66 = getelementptr inbounds i8, i8* %58, i64 %12
br label %67
67: ; preds = %57, %60, %50
%68 = phi i8* [ %66, %60 ], [ %56, %50 ], [ %47, %57 ]
%69 = call i32 @strlen(i8* %68)
%70 = call i32 @strncat(i8* %6, i8* %68, i32 %69)
%71 = call i64 @fputs(i8* %6, i32* %31)
%72 = load i64, i64* @EOF
%73 = icmp eq i64 %71, %72
br i1 %73, label %81, label %78
74: ; preds = %42
%75 = call i64 @fputs(i8* %3, i32* %31)
%76 = load i64, i64* @EOF
%77 = icmp eq i64 %75, %76
br i1 %77, label %81, label %78
78: ; preds = %74, %67
%79 = call i32* @fgets(i8* %3, i32 %1, i32* %22)
%80 = icmp eq i32* %79, null
br i1 %80, label %87, label %42
81: ; preds = %74, %67
%82 = load i32, i32* @stderr
%83 = load i32, i32* @errno
%84 = call i8* @strerror(i32 %83)
%85 = load i32, i32* @errno
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.11, i64 0, i64 0), i8* %84, i32 %85)
br label %87
87: ; preds = %78, %81, %33
%88 = call i32 @fclose(i32* %22)
%89 = call i32 @fclose(i32* %31)
%90 = call i64 @rename(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%91 = icmp eq i64 %90, 0
br i1 %91, label %98, label %92
92: ; preds = %87
%93 = load i32, i32* @stderr
%94 = load i32, i32* @errno
%95 = call i8* @strerror(i32 %94)
%96 = load i32, i32* @errno
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.12, i64 0, i64 0), i8* %95, i32 %96)
br label %98
98: ; preds = %87, %92, %38, %24, %15
%99 = phi i32 [ 1, %15 ], [ 1, %24 ], [ 1, %38 ], [ 1, %92 ], [ 0, %87 ]
ret i32 %99
}