#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 uint32_t;
typedef int /*<<< orphan*/ path;

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ O_WRONLY;
int close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
size_t strlen(char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ usleep(int);
size_t write(int, char *, int);
void transmit(uint32_t nhigh, uint32_t nlow, uint32_t pulse_len) {
  int fd;
  size_t n;
  int ret;
  char path[100] = {0};
  snprintf(path, sizeof(path) - 1, "/sys/class/gpio/gpio%s/value", "49");
  fd = open(path, O_WRONLY);
  if (fd == -1) {
    syslog(LOG_ERR, "Cannot open %s\n", path);
    exit(-1);
  }
  n = write(fd, "1", 1);
  if (n != strlen("1")) {
    syslog(LOG_ERR, "Cannot write\n");
    exit(-1);
  }
  usleep(pulse_len * nhigh);
  n = write(fd, "0", 1);
  if (n != strlen("0")) {
    syslog(LOG_ERR, "Cannot write\n");
    exit(-1);
  }
  usleep(pulse_len * nlow);
  ret = close(fd);
  if (ret == -1) {
    syslog(LOG_ERR, "Cannot close %s\n", path);
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<transmit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
lea    -0x80(%rbp),%rdi
mov    $0x63,%esi
lea    0xe3c(%rip),%rdx
lea    0xe52(%rip),%rcx
call   1050 <snprintf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1214 <transmit+0x84>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rdx
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%edi
lea    0xe12(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    0xdf2(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x88(%rbp),%rax
cmp    %rcx,%rax
je     1277 <transmit+0xe7>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0xc(%rbp),%edi
imul   -0x4(%rbp),%edi
call   10b0 <usleep@plt>
mov    -0x10(%rbp),%edi
lea    0xdb3(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    0xd93(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x90(%rbp),%rax
cmp    %rcx,%rax
je     12e6 <transmit+0x156>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
lea    0xd5d(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0xc(%rbp),%edi
imul   -0x8(%rbp),%edi
call   10b0 <usleep@plt>
mov    -0x10(%rbp),%edi
call   1070 <close@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    132c <transmit+0x19c>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rdx
lea    0xd27(%rip),%rsi
mov    $0x0,%al
call   1080 <syslog@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transmit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %edx,%r15d
mov    %esi,%r14d
mov    %edi,%ebp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xe4f(%rip),%rdx
lea    0xe65(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x63,%esi
call   1040 <snprintf@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1265 <transmit+0xf5>
mov    %eax,%ebx
lea    0xe45(%rip),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%rax
jne    1244 <transmit+0xd4>
imul   %r15d,%ebp
mov    %ebp,%edi
call   1090 <usleep@plt>
lea    0xe31(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%rax
jne    1244 <transmit+0xd4>
imul   %r14d,%r15d
mov    %r15d,%edi
call   1090 <usleep@plt>
mov    %ebx,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     1277 <transmit+0x107>
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
lea    0xdde(%rip),%rsi
xor    %eax,%eax
call   1060 <syslog@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
lea    0xdab(%rip),%rsi
jmp    1287 <transmit+0x117>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"/sys/class/gpio/gpio%s/value\00"
@.str.1 = [3 x i8] c"49\00"
@O_WRONLY = global i32 0
@LOG_ERR = global i32 0
@.str.2 = [16 x i8] c"Cannot open %s\0A\00"
@.str.3 = [2 x i8] c"1\00"
@.str.4 = [14 x i8] c"Cannot write\0A\00"
@.str.5 = [2 x i8] c"0\00"
@.str.6 = [17 x i8] c"Cannot close %s\0A\00"
define void @transmit(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca [100 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = bitcast [100 x i8]* %10 to i8*
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%13 = call i32 @snprintf(i8* %12, i32 99, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%15 = load i32, i32* @O_WRONLY
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %24
19: ; preds = %3
%20 = load i32, i32* @LOG_ERR
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%22 = call i32 (i32, i8*, ...) @syslog(i32 %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %3
%25 = load i32, i32* %7
%26 = call i64 @write(i32 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
store i64 %26, i64* %8
%27 = load i64, i64* %8
%28 = call i64 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = load i32, i32* @LOG_ERR
%32 = call i32 (i32, i8*, ...) @syslog(i32 %31, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %24
%35 = load i32, i32* %6
%36 = load i32, i32* %4
%37 = mul nsw i32 %35, %36
%38 = call i32 @usleep(i32 %37)
%39 = load i32, i32* %7
%40 = call i64 @write(i32 %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
store i64 %40, i64* %8
%41 = load i64, i64* %8
%42 = call i64 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%43 = icmp ne i64 %41, %42
br i1 %43, label %44, label %48
44: ; preds = %34
%45 = load i32, i32* @LOG_ERR
%46 = call i32 (i32, i8*, ...) @syslog(i32 %45, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 @exit(i32 -1)
unreachable
48: ; preds = %34
%49 = load i32, i32* %6
%50 = load i32, i32* %5
%51 = mul nsw i32 %49, %50
%52 = call i32 @usleep(i32 %51)
%53 = load i32, i32* %7
%54 = call i32 @close(i32 %53)
store i32 %54, i32* %9
%55 = load i32, i32* %9
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %62
57: ; preds = %48
%58 = load i32, i32* @LOG_ERR
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%60 = call i32 (i32, i8*, ...) @syslog(i32 %58, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %59)
%61 = call i32 @exit(i32 -1)
unreachable
62: ; preds = %48
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"/sys/class/gpio/gpio%s/value\00"
@.str.1 = [3 x i8] c"49\00"
@O_WRONLY = global i32 0
@LOG_ERR = global i32 0
@.str.2 = [16 x i8] c"Cannot open %s\0A\00"
@.str.3 = [2 x i8] c"1\00"
@.str.4 = [14 x i8] c"Cannot write\0A\00"
@.str.5 = [2 x i8] c"0\00"
@.str.6 = [17 x i8] c"Cannot close %s\0A\00"
define void @transmit(i32 %0, i32 %1, i32 %2) {
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = call i32 @snprintf(i8* %5, i32 99, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @O_WRONLY
%8 = call i32 @open(i8* %5, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i32, i32* @LOG_ERR
%12 = call i32 (i32, i8*, ...) @syslog(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %3
%15 = call i64 @write(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%16 = icmp eq i64 %15, 1
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = load i32, i32* @LOG_ERR
%19 = call i32 (i32, i8*, ...) @syslog(i32 %18, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %14
%22 = mul nsw i32 %2, %0
%23 = call i32 @usleep(i32 %22)
%24 = call i64 @write(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%25 = icmp eq i64 %24, 1
br i1 %25, label %30, label %26
26: ; preds = %21
%27 = load i32, i32* @LOG_ERR
%28 = call i32 (i32, i8*, ...) @syslog(i32 %27, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %21
%31 = mul nsw i32 %2, %1
%32 = call i32 @usleep(i32 %31)
%33 = call i32 @close(i32 %8)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = load i32, i32* @LOG_ERR
%37 = call i32 (i32, i8*, ...) @syslog(i32 %36, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%38 = call i32 @exit(i32 -1)
unreachable
39: ; preds = %30
ret void
}