#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int O_NOCTTY;
int O_RDWR;
int open(char *, int);
int /*<<< orphan*/ printf(char *, char *);
char *ptsname(int);
int main() {
  int fd;
  char *cp;
  fd = open("/dev/ptmx", O_NOCTTY | O_RDWR);
  cp = ptsname(fd);
  if (cp == NULL)
    return EXIT_FAILURE;
  printf("ptsname %s\n", cp);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
mov    0x2e99(%rip),%rax
or     (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <ptsname@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1188 <main+0x58>
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11a4 <main+0x74>
mov    -0x10(%rbp),%rsi
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2ea0(%rip),%rax
mov    0x2ea9(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xeb6(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%edi
call   1030 <ptsname@plt>
test   %rax,%rax
je     1173 <main+0x43>
lea    0xea8(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    0x2e57(%rip),%rax
jmp    117a <main+0x4a>
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/ptmx\00"
@O_NOCTTY = global i32 0
@O_RDWR = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [12 x i8] c"ptsname %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
%4 = load i32, i32* @O_NOCTTY
%5 = load i32, i32* @O_RDWR
%6 = or i32 %4, %5
%7 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = call i8* @ptsname(i32 %8)
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %1
br label %18
14: ; preds = %0
%15 = load i8*, i8** %3
%16 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_SUCCESS
store i32 %17, i32* %1
br label %18
18: ; preds = %14, %12
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/ptmx\00"
@O_NOCTTY = global i32 0
@O_RDWR = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [12 x i8] c"ptsname %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_NOCTTY
%2 = load i32, i32* @O_RDWR
%3 = or i32 %2, %1
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i8* @ptsname(i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %9
9: ; preds = %0, %7
%10 = phi i32* [ @EXIT_SUCCESS, %7 ], [ @EXIT_FAILURE, %0 ]
%11 = load i32, i32* %10
ret i32 %11
}