#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*/ abort();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, int);
int main(int arc, char *argv[]) {
  int res;
  unsigned int val;
  FILE *fp = fopen("/dev/null", "r");
  val = 0;
  res = fscanf(fp, "%n", &val);
  printf("Result of fscanf %%n = %d\n", res);
  printf("Scanned format = %d\n", val);
  res = fscanf(fp, "");
  printf("Result of fscanf \"\" = %d\n", res);
  if (res != 0)
    abort();
  res = fscanf(fp, "BLURB");
  printf("Result of fscanf \"BLURB\" = %d\n", res);
  if (res >= 0)
    abort();
  fclose(fp);
  return 0;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe7d(%rip),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe68(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe74(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe92(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe65(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
je     11f0 <main+0xa0>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%rdi
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe50(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
jl     1225 <main+0xd5>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
movl   $0x0,0x4(%rsp)
lea    0xe94(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <fscanf@plt>
lea    0xe81(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
lea    0xe8a(%rip),%rdi
call   1050 <printf@plt>
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <fscanf@plt>
mov    %eax,%ebp
lea    0xe80(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
test   %ebp,%ebp
jne    1200 <main+0xb0>
lea    0xe88(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <fscanf@plt>
mov    %eax,%ebp
lea    0xe7b(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
test   %ebp,%ebp
jns    1200 <main+0xb0>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/null\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%n\00"
@.str.3 = [27 x i8] c"Result of fscanf %%n = %d\0A\00"
@.str.4 = [21 x i8] c"Scanned format = %d\0A\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [26 x i8] c"Result of fscanf \22\22 = %d\0A\00"
@.str.7 = [6 x i8] c"BLURB\00"
@.str.8 = [31 x i8] c"Result of fscanf \22BLURB\22 = %d\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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = 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* %9, i32** %8
store i32 0, i32* %7
%10 = load i32*, i32** %8
%11 = call i32 (i32*, i8*, ...) @fscanf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %7
%15 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%16 = load i32*, i32** %8
%17 = call i32 (i32*, i8*, ...) @fscanf(i32* %16, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %2
%25 = load i32*, i32** %8
%26 = call i32 (i32*, i8*, ...) @fscanf(i32* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %6
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = call i32 (...) @abort()
unreachable
33: ; preds = %24
%34 = load i32*, i32** %8
%35 = call i32 @fclose(i32* %34)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/null\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%n\00"
@.str.3 = [27 x i8] c"Result of fscanf %%n = %d\0A\00"
@.str.4 = [21 x i8] c"Scanned format = %d\0A\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [26 x i8] c"Result of fscanf \22\22 = %d\0A\00"
@.str.7 = [6 x i8] c"BLURB\00"
@.str.8 = [31 x i8] c"Result of fscanf \22BLURB\22 = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = 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))
store i32 0, i32* %3
%6 = call i32 (i32*, i8*, ...) @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%7 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %6)
%8 = load i32, i32* %3
%9 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %8)
%10 = call i32 (i32*, i8*, ...) @fscanf(i32* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %10)
%12 = icmp eq i32 %10, 0
br i1 %12, label %15, label %13
13: ; preds = %2
%14 = call i32 (...) @abort()
unreachable
15: ; preds = %2
%16 = call i32 (i32*, i8*, ...) @fscanf(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i32 %16)
%18 = icmp sgt i32 %16, -1
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 (...) @abort()
unreachable
21: ; preds = %15
%22 = call i32 @fclose(i32* %5)
ret i32 0
}