#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 */
struct image {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct image *newimage(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
struct image *imageopen2(char *filename) {
  struct image *i;
  FILE *f;
  if ((f = fopen(filename, "rb"))) {
    if ((i = newimage(f))) {
      return i;
    } else
      fprintf(stderr, "Invalid format '%s'\n", filename);
  } else {
    fprintf(stderr, "Cannot open '%s'\n", filename);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<imageopen2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     119c <imageopen2+0x6c>
mov    -0x20(%rbp),%rdi
call   1040 <newimage@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     117e <imageopen2+0x4e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11bd <imageopen2+0x8d>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe71(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11b5 <imageopen2+0x85>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe68(%rip),%rsi
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imageopen2>:
push   %rbx
mov    %rdi,%rbx
lea    0xec5(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1154 <imageopen2+0x24>
mov    %rax,%rdi
call   1040 <newimage@plt>
test   %rax,%rax
je     115d <imageopen2+0x2d>
pop    %rbx
ret
lea    0xebd(%rip),%rsi
jmp    1164 <imageopen2+0x34>
lea    0xe9f(%rip),%rsi
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.image = type { i32 }
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Invalid format '%s'\0A\00"
@.str.2 = [18 x i8] c"Cannot open '%s'\0A\00"
define %struct.image* @imageopen2(i8* %0) {
%2 = alloca %struct.image*
%3 = alloca i8*
%4 = alloca %struct.image*
%5 = alloca i32*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %20
9: ; preds = %1
%10 = load i32*, i32** %5
%11 = call %struct.image* @newimage(i32* %10)
store %struct.image* %11, %struct.image** %4
%12 = icmp ne %struct.image* %11, null
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = load %struct.image*, %struct.image** %4
store %struct.image* %14, %struct.image** %2
br label %25
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %3
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %15
br label %24
20: ; preds = %1
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %3
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %20, %19
store %struct.image* null, %struct.image** %2
br label %25
25: ; preds = %24, %13
%26 = load %struct.image*, %struct.image** %2
ret %struct.image* %26
}

LLVM IR (-O2):
%struct.image = type { i32 }
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Invalid format '%s'\0A\00"
@.str.2 = [18 x i8] c"Cannot open '%s'\0A\00"
define %struct.image* @imageopen2(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call %struct.image* @newimage(i32* %2)
%6 = icmp eq %struct.image* %5, null
br i1 %6, label %7, label %11
7: ; preds = %1, %4
%8 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), %1 ]
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* %8, i8* %0)
br label %11
11: ; preds = %7, %4
%12 = phi %struct.image* [ %5, %4 ], [ null, %7 ]
ret %struct.image* %12
}