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

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int fprintf(int /*<<< orphan*/ *, char *, int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int do_test(void) {
  int ret;
  FILE *fp = fopen("/dev/null", "w");
  if (fp == NULL) {
    puts("cannot open /dev/null");
    return 1;
  }
  ret = fprintf(fp,
                "%"
                "2147483648"
                "d%"
                "2147483648"
                "d",
                1, 1);
  printf("ret = %d\n", ret);
  return ret != -1;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xebf(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1182 <do_test+0x42>
lea    0xe91(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ba <do_test+0x7a>
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
mov    $0x1,%ecx
mov    %ecx,%edx
call   1050 <fprintf@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe8b(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0xffffffff,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rbx
lea    0xec6(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     118c <do_test+0x4c>
lea    0xeb8(%rip),%rsi
mov    %rax,%rdi
mov    $0x1,%edx
mov    $0x1,%ecx
call   1050 <fprintf@plt>
mov    %eax,%ebx
lea    0xeb6(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
cmp    $0xffffffff,%ebx
setne  %al
pop    %rbx
ret
lea    0xe6f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/null\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [22 x i8] c"cannot open /dev/null\00"
@.str.3 = [25 x i8] c"%2147483648d%2147483648d\00"
@.str.4 = [10 x i8] c"ret = %d\0A\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = load i32*, i32** %3
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %17
9: ; preds = %0
%10 = load i32*, i32** %3
%11 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 1)
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %2
%15 = icmp ne i32 %14, -1
%16 = zext i1 %15 to i32
store i32 %16, i32* %1
br label %17
17: ; preds = %9, %7
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/null\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [22 x i8] c"cannot open /dev/null\00"
@.str.3 = [25 x i8] c"%2147483648d%2147483648d\00"
@.str.4 = [10 x i8] c"ret = %d\0A\00"
define i32 @do_test() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %10
5: ; preds = %0
%6 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 1)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %6)
%8 = icmp ne i32 %6, -1
%9 = zext i1 %8 to i32
br label %10
10: ; preds = %5, %3
%11 = phi i32 [ 1, %3 ], [ %9, %5 ]
ret i32 %11
}