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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, int, int);
void main() {
  int fd1, fd2, fd3;
  char *file1 = "/sdcard/t.txt";
  char *file2 = "/sdcard/t1.txt";
  char *file3 = "/sdcard/t2.txt";
  fd1 = open(file1, O_RDONLY);
  fd2 = open(file2, O_RDONLY);
  fd3 = open(file3, O_RDONLY);
  printf("fd1=%d fd2=%d fd3=%d\n", fd1, fd2, fd3);
  close(fd2);
  exit(2);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb1(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xeb4(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xeb8(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    $0x2,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e9d(%rip),%rbx
mov    (%rbx),%esi
lea    0xeac(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%r14d
mov    (%rbx),%esi
lea    0xea9(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebp
mov    (%rbx),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
lea    0xeab(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %eax,%ecx
call   1030 <printf@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    $0x2,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/sdcard/t.txt\00"
@.str.1 = [15 x i8] c"/sdcard/t1.txt\00"
@.str.2 = [15 x i8] c"/sdcard/t2.txt\00"
@O_RDONLY = global i32 0
@.str.3 = [22 x i8] c"fd1=%d fd2=%d fd3=%d\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8** %6
%7 = load i8*, i8** %4
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %1
%10 = load i8*, i8** %5
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %2
%13 = load i8*, i8** %6
%14 = load i32, i32* @O_RDONLY
%15 = call i32 @open(i8* %13, i32 %14)
store i32 %15, i32* %3
%16 = load i32, i32* %1
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %16, i32 %17, i32 %18)
%20 = load i32, i32* %2
%21 = call i32 @close(i32 %20)
%22 = call i32 @exit(i32 2)
unreachable
}

LLVM IR (-O2):
@.str = [14 x i8] c"/sdcard/t.txt\00"
@.str.1 = [15 x i8] c"/sdcard/t1.txt\00"
@.str.2 = [15 x i8] c"/sdcard/t2.txt\00"
@O_RDONLY = global i32 0
@.str.3 = [22 x i8] c"fd1=%d fd2=%d fd3=%d\0A\00"
define void @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %2, i32 %4, i32 %6)
%8 = tail call i32 @close(i32 %4)
%9 = tail call i32 @exit(i32 2)
unreachable
}