#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 argc, char **argv) {
  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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    0x2e92(%rip),%rax
or     (%rax),%esi
lea    0xea1(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <ptsname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118f <main+0x5f>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <main+0x7b>
mov    -0x20(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%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(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @O_NOCTTY
%9 = load i32, i32* @O_RDWR
%10 = or i32 %8, %9
%11 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = call i8* @ptsname(i32 %12)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = load i32, i32* @EXIT_FAILURE
store i32 %17, i32* %3
br label %22
18: ; preds = %2
%19 = load i8*, i8** %7
%20 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_SUCCESS
store i32 %21, i32* %3
br label %22
22: ; preds = %18, %16
%23 = load i32, i32* %3
ret i32 %23
}

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(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_NOCTTY
%4 = load i32, i32* @O_RDWR
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i8* @ptsname(i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %11
11: ; preds = %2, %9
%12 = phi i32* [ @EXIT_SUCCESS, %9 ], [ @EXIT_FAILURE, %2 ]
%13 = load i32, i32* %12
ret i32 %13
}