#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*/ uint8_t;
typedef int uint32_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ alloc_image(int, int, size_t);
scalar_t__ atol(char *);
int create_image(char *, int /*<<< orphan*/ **, int, int);
scalar_t__ fill(int /*<<< orphan*/ **, int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free_bmp();
int /*<<< orphan*/ free_image(void **);
int open_image(char *, int *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ **seam_carving(int /*<<< orphan*/ **, int, int, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  uint32_t new_width, return_value;
  uint32_t nl, nc;
  char *filename, *destination;
  uint8_t **image;
  uint8_t **result_image;
  if (argc != 4) {
    printf("usage: ./seamcarving IMAGE_FILE NEW_WIDTH DESTINATION_FILE\n");
    return EXIT_FAILURE;
  }
  new_width = (uint32_t)atol(argv[2]);
  filename = argv[1];
  destination = argv[3];
  return_value = open_image(filename, &nl, &nc);
  if (return_value != 0)
    switch (return_value) {
    case 0xDEADBEEF:
      printf("error: can't find file \'%s\'\n", filename);
      return EXIT_FAILURE;
    case 0xBEEFDEAD:
      printf("error: file \'%s\'\n not supported\n", filename);
      return EXIT_FAILURE;
    case 0xDEADB00B:
      printf("error: invalid file \'%s\'\n", filename);
      return EXIT_FAILURE;
    default:
      do {
        fprintf(stderr, "ERROR: %s:%d\t\t",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/HugZz/seamcarving/refs/"
                "heads/main/src/main.c",
                55);
        fprintf(stderr, "error opening file \'%s\'\n", filename);
      } while (0);
      return EXIT_FAILURE;
    }
  if (new_width == nc) {
    printf("%d is the width of the given image, nothing to do\n", new_width);
    free_bmp();
    return EXIT_SUCCESS;
  }
  if (new_width > nc) {
    printf("error: wanted width %d is bigger than original image\n", new_width);
    free_bmp();
    return EXIT_FAILURE;
  }
  if ((image = (uint8_t **)alloc_image(nl, nc, ((size_t)1))) == NULL) {
    do {
      fprintf(stderr, "ERROR: %s:%d\t\t",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/HugZz/seamcarving/refs/heads/main/src/"
              "main.c",
              71);
      fprintf(stderr, "allocating image failed\n");
    } while (0);
    free_bmp();
    return EXIT_FAILURE;
  }
  if (fill(image, nl, nc) < 0) {
    do {
      fprintf(stderr, "ERROR: %s:%d\t\t",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/HugZz/seamcarving/refs/heads/main/src/"
              "main.c",
              76);
      fprintf(stderr, "problem filling the image\n");
    } while (0);
    free_bmp();
    free_image((void **)image);
    return EXIT_FAILURE;
  }
  free_bmp();
  result_image = seam_carving(image, nc - new_width, nl, nc);
  if (result_image == NULL) {
    do {
      fprintf(stderr, "ERROR: %s:%d\t\t",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/HugZz/seamcarving/refs/heads/main/src/"
              "main.c",
              84);
      fprintf(stderr, "error seam carving the image\n");
    } while (0);
    free_image((void **)image);
    return EXIT_FAILURE;
  }
  free_image((void **)image);
  return_value = create_image(destination, result_image, nl, new_width);
  if (return_value < 0) {
    do {
      fprintf(stderr, "ERROR: %s:%d\t\t",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/HugZz/seamcarving/refs/heads/main/src/"
              "main.c",
              91);
      fprintf(stderr, "can not create image\n");
    } while (0);
    free_image((void **)result_image);
    return EXIT_FAILURE;
  }
  free_image((void **)result_image);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11df <main+0x3f>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1591 <main+0x3f1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10b0 <open_image@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     131e <main+0x17e>
mov    -0x18(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0xbeefdead,%eax
je     1284 <main+0xe4>
jmp    123b <main+0x9b>
mov    -0x44(%rbp),%eax
sub    $0xdeadb00b,%eax
je     12a7 <main+0x107>
jmp    124e <main+0xae>
mov    -0x44(%rbp),%eax
sub    $0xdeadbeef,%eax
jne    12ca <main+0x12a>
jmp    1261 <main+0xc1>
mov    -0x28(%rbp),%rsi
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1591 <main+0x3f1>
mov    -0x28(%rbp),%rsi
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1591 <main+0x3f1>
mov    -0x28(%rbp),%rsi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1591 <main+0x3f1>
jmp    12cf <main+0x12f>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
lea    0xdb5(%rip),%rsi
lea    0xdbd(%rip),%rdx
mov    $0x37,%ecx
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2ce7(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2cc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1591 <main+0x3f1>
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    1353 <main+0x1b3>
mov    -0x14(%rbp),%esi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <free_bmp@plt>
mov    0x2c87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1591 <main+0x3f1>
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    1388 <main+0x1e8>
mov    -0x14(%rbp),%esi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <free_bmp@plt>
mov    0x2c5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1591 <main+0x3f1>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    $0x1,%edx
call   1090 <alloc_image@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    13fd <main+0x25d>
jmp    13ab <main+0x20b>
mov    0x2c2e(%rip),%rax
mov    (%rax),%edi
lea    0xcd9(%rip),%rsi
lea    0xce1(%rip),%rdx
mov    $0x47,%ecx
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2c0b(%rip),%rax
mov    (%rax),%edi
lea    0xdce(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x0,%al
call   1060 <free_bmp@plt>
mov    0x2be5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1591 <main+0x3f1>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1070 <fill@plt>
cmp    $0x0,%rax
jge    1476 <main+0x2d6>
jmp    141b <main+0x27b>
mov    0x2bbe(%rip),%rax
mov    (%rax),%edi
lea    0xc69(%rip),%rsi
lea    0xc71(%rip),%rdx
mov    $0x4c,%ecx
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2b9b(%rip),%rax
mov    (%rax),%edi
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x0,%al
call   1060 <free_bmp@plt>
mov    -0x38(%rbp),%rdi
call   1040 <free_image@plt>
mov    0x2b6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1591 <main+0x3f1>
mov    $0x0,%al
call   1060 <free_bmp@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%esi
sub    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1030 <seam_carving@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    14fa <main+0x35a>
jmp    14a6 <main+0x306>
mov    0x2b33(%rip),%rax
mov    (%rax),%edi
lea    0xbde(%rip),%rsi
lea    0xbe6(%rip),%rdx
mov    $0x54,%ecx
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2b10(%rip),%rax
mov    (%rax),%edi
lea    0xd07(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1040 <free_image@plt>
mov    0x2ae8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1591 <main+0x3f1>
mov    -0x38(%rbp),%rdi
call   1040 <free_image@plt>
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   10c0 <create_image@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    157c <main+0x3dc>
jmp    1528 <main+0x388>
mov    0x2ab1(%rip),%rax
mov    (%rax),%edi
lea    0xb5c(%rip),%rsi
lea    0xb64(%rip),%rdx
mov    $0x5b,%ecx
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2a8e(%rip),%rax
mov    (%rax),%edi
lea    0xca3(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1040 <free_image@plt>
mov    0x2a66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1591 <main+0x3f1>
mov    -0x40(%rbp),%rdi
call   1040 <free_image@plt>
mov    0x2a44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x4,%edi
jne    1202 <main+0x52>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
call   10b0 <atol@plt>
mov    %rax,%r12
mov    0x8(%rbx),%r14
mov    0x18(%rbx),%r15
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
call   10c0 <open_image@plt>
cmp    $0xdeadbeee,%eax
jg     1213 <main+0x63>
cmp    $0xbeefdead,%eax
je     1227 <main+0x77>
cmp    $0xdeadb00b,%eax
jne    126a <main+0xba>
lea    0xe3e(%rip),%rdi
jmp    122e <main+0x7e>
lea    0xfcf(%rip),%rdi
call   1040 <puts@plt>
jmp    142f <main+0x27f>
test   %eax,%eax
je     123d <main+0x8d>
cmp    $0xdeadbeef,%eax
jne    126a <main+0xba>
lea    0xddb(%rip),%rdi
jmp    122e <main+0x7e>
lea    0xdef(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    142f <main+0x27f>
mov    0x4(%rsp),%esi
cmp    %r12d,%esi
jne    12a5 <main+0xf5>
lea    0xeba(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <free_bmp@plt>
mov    0x2d6b(%rip),%rax
jmp    1436 <main+0x286>
mov    0x2d6f(%rip),%rbx
mov    (%rbx),%edi
lea    0xdde(%rip),%rsi
lea    0xde6(%rip),%rdx
mov    $0x37,%ecx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe58(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    142f <main+0x27f>
jge    12bd <main+0x10d>
lea    0xe8c(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1372 <main+0x1c2>
mov    (%rsp),%edi
mov    $0x1,%edx
call   10a0 <alloc_image@plt>
test   %rax,%rax
je     133f <main+0x18f>
mov    %rax,%r14
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
mov    %rax,%rdi
call   1080 <fill@plt>
test   %rax,%rax
js     137e <main+0x1ce>
xor    %eax,%eax
call   1070 <free_bmp@plt>
mov    0x4(%rsp),%ecx
mov    %ecx,%esi
sub    %r12d,%esi
mov    (%rsp),%edx
mov    %r14,%rdi
call   1030 <seam_carving@plt>
test   %rax,%rax
je     13ba <main+0x20a>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <free_image@plt>
mov    (%rsp),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12d,%ecx
call   10d0 <create_image@plt>
test   %eax,%eax
js     13f2 <main+0x242>
mov    %rbx,%rdi
call   1050 <free_image@plt>
jmp    125e <main+0xae>
mov    0x2c9a(%rip),%rbx
mov    (%rbx),%edi
lea    0xd09(%rip),%rsi
lea    0xd11(%rip),%rdx
mov    $0x47,%ecx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe05(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
xor    %eax,%eax
call   1070 <free_bmp@plt>
jmp    142f <main+0x27f>
mov    0x2c5b(%rip),%rbx
mov    (%rbx),%edi
lea    0xcca(%rip),%rsi
lea    0xcd2(%rip),%rdx
mov    $0x4c,%ecx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rbx),%edi
lea    0xddf(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
xor    %eax,%eax
call   1070 <free_bmp@plt>
jmp    13ed <main+0x23d>
mov    0x2c1f(%rip),%rbx
mov    (%rbx),%edi
lea    0xc8e(%rip),%rsi
lea    0xc96(%rip),%rdx
mov    $0x54,%ecx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdbe(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14,%rdi
jmp    142a <main+0x27a>
mov    0x2be7(%rip),%r14
mov    (%r14),%edi
lea    0xc55(%rip),%rsi
lea    0xc5d(%rip),%rdx
mov    $0x5b,%ecx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%r14),%edi
lea    0xda2(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <free_image@plt>
mov    0x2ba2(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [60 x i8] c"usage: ./seamcarving IMAGE_FILE NEW_WIDTH DESTINATION_FILE\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [29 x i8] c"error: can't find file '%s'\0A\00"
@.str.2 = [33 x i8] c"error: file '%s'\0A not supported\0A\00"
@.str.3 = [26 x i8] c"error: invalid file '%s'\0A\00"
@stderr = global i32 0
@.str.4 = [15 x i8] c"ERROR: %s:%d\09\09\00"
@.str.5 = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/HugZz/seamcarving/refs/heads/main/src/main.c\00"
@.str.6 = [25 x i8] c"error opening file '%s'\0A\00"
@.str.7 = [51 x i8] c"%d is the width of the given image, nothing to do\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.8 = [54 x i8] c"error: wanted width %d is bigger than original image\0A\00"
@.str.9 = [25 x i8] c"allocating image failed\0A\00"
@.str.10 = [27 x i8] c"problem filling the image\0A\00"
@.str.11 = [30 x i8] c"error seam carving the image\0A\00"
@.str.12 = [22 x i8] c"can not create image\0A\00"
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 i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32**
%13 = alloca i32**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 4
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %3
br label %158
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i64 @atol(i8* %22)
%24 = trunc i64 %23 to i32
store i32 %24, i32* %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
store i8* %27, i8** %10
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 3
%30 = load i8*, i8** %29
store i8* %30, i8** %11
%31 = load i8*, i8** %10
%32 = call i32 @open_image(i8* %31, i32* %8, i32* %9)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %58
35: ; preds = %19
%36 = load i32, i32* %7
switch i32 %36, label %49 [
i32 -559038737, label %37
i32 -1091576147, label %41
i32 -559042549, label %45
]
37: ; preds = %35
%38 = load i8*, i8** %10
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
store i32 %40, i32* %3
br label %158
41: ; preds = %35
%42 = load i8*, i8** %10
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @EXIT_FAILURE
store i32 %44, i32* %3
br label %158
45: ; preds = %35
%46 = load i8*, i8** %10
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
store i32 %48, i32* %3
br label %158
49: ; preds = %35
br label %50
50: ; preds = %49
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.5, i64 0, i64 0), i32 55)
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %10
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %50
%57 = load i32, i32* @EXIT_FAILURE
store i32 %57, i32* %3
br label %158
58: ; preds = %19
%59 = load i32, i32* %6
%60 = load i32, i32* %9
%61 = icmp eq i32 %59, %60
br i1 %61, label %62, label %67
62: ; preds = %58
%63 = load i32, i32* %6
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.7, i64 0, i64 0), i32 %63)
%65 = call i32 (...) @free_bmp()
%66 = load i32, i32* @EXIT_SUCCESS
store i32 %66, i32* %3
br label %158
67: ; preds = %58
%68 = load i32, i32* %6
%69 = load i32, i32* %9
%70 = icmp sgt i32 %68, %69
br i1 %70, label %71, label %76
71: ; preds = %67
%72 = load i32, i32* %6
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0), i32 %72)
%74 = call i32 (...) @free_bmp()
%75 = load i32, i32* @EXIT_FAILURE
store i32 %75, i32* %3
br label %158
76: ; preds = %67
%77 = load i32, i32* %8
%78 = load i32, i32* %9
%79 = call i64 @alloc_image(i32 %77, i32 %78, i64 1)
%80 = inttoptr i64 %79 to i32**
store i32** %80, i32*** %12
%81 = icmp eq i32** %80, null
br i1 %81, label %82, label %91
82: ; preds = %76
br label %83
83: ; preds = %82
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.5, i64 0, i64 0), i32 71)
%86 = load i32, i32* @stderr
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
br label %88
88: ; preds = %83
%89 = call i32 (...) @free_bmp()
%90 = load i32, i32* @EXIT_FAILURE
store i32 %90, i32* %3
br label %158
91: ; preds = %76
%92 = load i32**, i32*** %12
%93 = load i32, i32* %8
%94 = load i32, i32* %9
%95 = call i64 @fill(i32** %92, i32 %93, i32 %94)
%96 = icmp slt i64 %95, 0
br i1 %96, label %97, label %109
97: ; preds = %91
br label %98
98: ; preds = %97
%99 = load i32, i32* @stderr
%100 = call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.5, i64 0, i64 0), i32 76)
%101 = load i32, i32* @stderr
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
br label %103
103: ; preds = %98
%104 = call i32 (...) @free_bmp()
%105 = load i32**, i32*** %12
%106 = bitcast i32** %105 to i8**
%107 = call i32 @free_image(i8** %106)
%108 = load i32, i32* @EXIT_FAILURE
store i32 %108, i32* %3
br label %158
109: ; preds = %91
%110 = call i32 (...) @free_bmp()
%111 = load i32**, i32*** %12
%112 = load i32, i32* %9
%113 = load i32, i32* %6
%114 = sub nsw i32 %112, %113
%115 = load i32, i32* %8
%116 = load i32, i32* %9
%117 = call i32** @seam_carving(i32** %111, i32 %114, i32 %115, i32 %116)
store i32** %117, i32*** %13
%118 = load i32**, i32*** %13
%119 = icmp eq i32** %118, null
br i1 %119, label %120, label %131
120: ; preds = %109
br label %121
121: ; preds = %120
%122 = load i32, i32* @stderr
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.5, i64 0, i64 0), i32 84)
%124 = load i32, i32* @stderr
%125 = call i32 (i32, i8*, ...) @fprintf(i32 %124, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0))
br label %126
126: ; preds = %121
%127 = load i32**, i32*** %12
%128 = bitcast i32** %127 to i8**
%129 = call i32 @free_image(i8** %128)
%130 = load i32, i32* @EXIT_FAILURE
store i32 %130, i32* %3
br label %158
131: ; preds = %109
%132 = load i32**, i32*** %12
%133 = bitcast i32** %132 to i8**
%134 = call i32 @free_image(i8** %133)
%135 = load i8*, i8** %11
%136 = load i32**, i32*** %13
%137 = load i32, i32* %8
%138 = load i32, i32* %6
%139 = call i32 @create_image(i8* %135, i32** %136, i32 %137, i32 %138)
store i32 %139, i32* %7
%140 = load i32, i32* %7
%141 = icmp slt i32 %140, 0
br i1 %141, label %142, label %153
142: ; preds = %131
br label %143
143: ; preds = %142
%144 = load i32, i32* @stderr
%145 = call i32 (i32, i8*, ...) @fprintf(i32 %144, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.5, i64 0, i64 0), i32 91)
%146 = load i32, i32* @stderr
%147 = call i32 (i32, i8*, ...) @fprintf(i32 %146, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
br label %148
148: ; preds = %143
%149 = load i32**, i32*** %13
%150 = bitcast i32** %149 to i8**
%151 = call i32 @free_image(i8** %150)
%152 = load i32, i32* @EXIT_FAILURE
store i32 %152, i32* %3
br label %158
153: ; preds = %131
%154 = load i32**, i32*** %13
%155 = bitcast i32** %154 to i8**
%156 = call i32 @free_image(i8** %155)
%157 = load i32, i32* @EXIT_SUCCESS
store i32 %157, i32* %3
br label %158
158: ; preds = %153, %148, %126, %103, %88, %71, %62, %56, %45, %41, %37, %16
%159 = load i32, i32* %3
ret i32 %159
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [29 x i8] c"error: can't find file '%s'\0A\00"
@.str.2 = [33 x i8] c"error: file '%s'\0A not supported\0A\00"
@.str.3 = [26 x i8] c"error: invalid file '%s'\0A\00"
@stderr = global i32 0
@.str.4 = [15 x i8] c"ERROR: %s:%d\09\09\00"
@.str.5 = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/HugZz/seamcarving/refs/heads/main/src/main.c\00"
@.str.6 = [25 x i8] c"error opening file '%s'\0A\00"
@.str.7 = [51 x i8] c"%d is the width of the given image, nothing to do\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.8 = [54 x i8] c"error: wanted width %d is bigger than original image\0A\00"
@.str.9 = [25 x i8] c"allocating image failed\0A\00"
@.str.10 = [27 x i8] c"problem filling the image\0A\00"
@.str.11 = [30 x i8] c"error seam carving the image\0A\00"
@.str.12 = [22 x i8] c"can not create image\0A\00"
@str = [59 x i8] c"usage: ./seamcarving IMAGE_FILE NEW_WIDTH DESTINATION_FILE\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32 %0, 4
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str, i64 0, i64 0))
br label %96
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i64 @atol(i8* %12)
%14 = trunc i64 %13 to i32
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = call i32 @open_image(i8* %16, i32* %3, i32* %4)
switch i32 %19, label %26 [
i32 0, label %31
i32 -559038737, label %20
i32 -1091576147, label %22
i32 -559042549, label %24
]
20: ; preds = %10
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %96
22: ; preds = %10
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %96
24: ; preds = %10
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %16)
br label %96
26: ; preds = %10
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.5, i64 0, i64 0), i32 55)
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8* %16)
br label %96
31: ; preds = %10
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, %14
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.7, i64 0, i64 0), i32 %14)
%36 = call i32 (...) @free_bmp()
br label %96
37: ; preds = %31
%38 = icmp slt i32 %32, %14
br i1 %38, label %39, label %42
39: ; preds = %37
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0), i32 %14)
%41 = call i32 (...) @free_bmp()
br label %96
42: ; preds = %37
%43 = load i32, i32* %3
%44 = call i64 @alloc_image(i32 %43, i32 %32, i64 1)
%45 = inttoptr i64 %44 to i32**
%46 = icmp eq i64 %44, 0
br i1 %46, label %47, label %53
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.5, i64 0, i64 0), i32 71)
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
%52 = call i32 (...) @free_bmp()
br label %96
53: ; preds = %42
%54 = load i32, i32* %3
%55 = load i32, i32* %4
%56 = call i64 @fill(i32** %45, i32 %54, i32 %55)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %66
58: ; preds = %53
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.5, i64 0, i64 0), i32 76)
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
%63 = call i32 (...) @free_bmp()
%64 = inttoptr i64 %44 to i8**
%65 = call i32 @free_image(i8** %64)
br label %96
66: ; preds = %53
%67 = call i32 (...) @free_bmp()
%68 = load i32, i32* %4
%69 = sub nsw i32 %68, %14
%70 = load i32, i32* %3
%71 = call i32** @seam_carving(i32** %45, i32 %69, i32 %70, i32 %68)
%72 = icmp eq i32** %71, null
br i1 %72, label %73, label %80
73: ; preds = %66
%74 = load i32, i32* @stderr
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.5, i64 0, i64 0), i32 84)
%76 = load i32, i32* @stderr
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0))
%78 = inttoptr i64 %44 to i8**
%79 = call i32 @free_image(i8** %78)
br label %96
80: ; preds = %66
%81 = inttoptr i64 %44 to i8**
%82 = call i32 @free_image(i8** %81)
%83 = load i32, i32* %3
%84 = call i32 @create_image(i8* %18, i32** %71, i32 %83, i32 %14)
%85 = icmp slt i32 %84, 0
br i1 %85, label %86, label %93
86: ; preds = %80
%87 = load i32, i32* @stderr
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.5, i64 0, i64 0), i32 91)
%89 = load i32, i32* @stderr
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
%91 = bitcast i32** %71 to i8**
%92 = call i32 @free_image(i8** %91)
br label %96
93: ; preds = %80
%94 = bitcast i32** %71 to i8**
%95 = call i32 @free_image(i8** %94)
br label %96
96: ; preds = %93, %86, %73, %58, %47, %39, %34, %26, %24, %22, %20, %8
%97 = phi i32* [ @EXIT_FAILURE, %8 ], [ @EXIT_FAILURE, %26 ], [ @EXIT_FAILURE, %24 ], [ @EXIT_FAILURE, %22 ], [ @EXIT_FAILURE, %20 ], [ @EXIT_SUCCESS, %34 ], [ @EXIT_FAILURE, %39 ], [ @EXIT_FAILURE, %47 ], [ @EXIT_FAILURE, %58 ], [ @EXIT_FAILURE, %73 ], [ @EXIT_FAILURE, %86 ], [ @EXIT_SUCCESS, %93 ]
%98 = load i32, i32* %97
ret i32 %98
}